1

因此,我正在开发一个程序来获取数据“.txt”格式并读取某些值,然后将这些值放入外部报告中,该报告格式化为我公司使用的标准文档。然后复制格式化的文档并将它们保存在单独的工作簿中,这将是格式化工作表的集体数据库,供以后查看或打印出来。

显然,我已经将这段代码简化为我的问题发生的地方,但它仍然代表了我的基本想法,并导致与较大文件相同的警报。

Sub Begin()
Workbooks.Open Filename:="C:\Users\CNCLathe.MANDA\Desktop\XL\COPYING\Report1.xlsx"
Workbooks.Open Filename:="C:\Users\CNCLathe.MANDA\Desktop\XL\COPYING\Report2.xlsx"
'---------------------------------------------------------------------------------
'The File With the Sub Program organizing information
Set W1 = Workbooks("TEST.xlsm")

'The File With the Formatted Worksheet
'Changes will not be saved when it closes
Set W2 = Workbooks("Report1.xlsx")

'The File with all the new formatted worksheets added to it
Set W3 = Workbooks("Report2.xlsx")
'---------------------------------------------------------------------------------
'pretending to add data to formatted file as I will later
W2.Sheets("Sheet1").Cells(2, 2).Value = 999



'then I need to copy the formated worksheet[as values] 
'and add it to Report2

'Error Occurs here
W2.Sheets("Sheet1").Copy After:=W1.Sheets(wb.Sheets.Count)

'ActiveSheet.UsedRange.Value = ActiveSheet.UsedRange.Value







Workbooks("Report1.xlsx").Activate
MsgBox ("OPEN")
'ActiveWorkbook.Save
ActiveWorkbook.Close SaveChanges:=False
End Sub
4

1 回答 1

2

在哪里wb定义?也许代替wb.Sheets.Count, 尝试W1.Sheets.Count

于 2013-08-22T21:11:35.397 回答