如何将数据转储到工作簿并保存副本?

时间:2014-03-28 23:44:26

标签: excel vba

我有一个记录集UserTab我要复制到Excel电子表格(它需要格式化)然后保存副本

Dim templatewb As Workbook
templatewb = application.open("C:\ \ .xlsx") // I also tried add

templatewb.Worksheets("Sheet1").Cells("A1").CopyFromRecordset UserTab 
templatewb.close  savechanges:=true filename:="c:...copyOfATemplate.xls"

我得到以下

Method 'Save' of object '_Workbook' failed

1 个答案:

答案 0 :(得分:3)

Dim templatewb As Workbook

Set templatewb = workbooks.open("C:\stuff\templt.xlsx") 'need Set here...

templatewb.Worksheets("Sheet1").Range("A1").CopyFromRecordset UserTab 

templatewb.SaveAs  "C:\stuff\copyOfATemplate.xls"