0
我正在嘗試在少數Excel表格上使用以下代碼執行少量操作。我得到一個運行時錯誤1004 Application.Workbooks.Open(StrFile)。它似乎無法找到該文件。之所以我認爲,這是因爲它沒有顯示在下面的截圖顯示在目錄中的文件路徑,但只是文件:在循環中打開Excel工作表時發生VBA錯誤
Sub ExcelerFinal()
Dim FileCount As Integer
Dim FileName As String, FileNameGIS As String
Dim FilePath As String, StrFile As String
FileCount = 0
FileName = "MyFile_" + CStr(FileCount)
FileNameGIS = "MyFileGIS_" + CStr(FileCount)
FilePath = "E:\Database Project\ACS Estimate 2011\LoopTest\Test_RawData\"
StrFile = Dir(FilePath & "*.xlsx")
While StrFile <> ""
Application.Workbooks.Open (StrFile) 'Error occurs on this line
FileCount = FileCount + 1
FileName = "MyFile_" + CStr(FileCount)
FileNameGIS = "MyFileGIS_" + CStr(FileCount)
' Lots of code to manipulate file
' unrelated to issue
Windows(FileNameGIS).Close
StrFile = Dir
Wend
End Sub