我正在尝试在少数excel表上执行一些程序并使用以下代码。我收到 Application.Workbooks.Open(StrFile)的运行时错误1004。好像它无法找到该文件。我认为这是因为它没有显示文件路径,而只是显示在屏幕截图中显示的目录中的文件:
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
答案 0 :(得分:1)
改为使用:
Application.Workbooks.Open(FilePath & strFile)