【发布时间】:2015-04-25 02:33:00
【问题描述】:
有人可以帮我解决以下问题: 我在“11-12 财年”文件夹中有大约 12 个工作簿。所有 12 个文件都有一个名为“Categorized”的通用工作表。我正在尝试将数据从所有文件的该表传输到文件 YearlyExpense.xlsm,但出现以下错误:
运行时错误 1004。找不到“xxx.xlsx”。检查 名称的拼写,并验证文件位置是否正确。
我的代码如下:
Sub LoopThroughDirectory()
Dim MyFile As String
Dim erow
MyFile = Dir("C:\Users\Winston\Documents\Family Budget\Fiscal Year 11-12\")
Do While Len(MyFile) > 0
If MyFile = "YearlyExpense.Xlsm" Then
Exit Sub
End If
Workbooks.Open (MyFile)
'This is where I'm getting error 1004 vba
Sheets("Categorized").Select
Range("B32:V32").Copy
ActiveWorkbook.Close
erow = Sheet2.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
ActiveSheet.Paste Destination:=Worksheets("sheet2").Range(Cells(erow, 1), Cells(erow, 22))
MyFile = Dir
Loop
结束子
【问题讨论】: