0

我正在尝试在几个 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
4

1 回答 1

1

改用:

Application.Workbooks.Open(FilePath & strFile)
于 2013-03-06T18:28:04.013 回答