0

I am trying to perform few procedure on few excel sheets and using the following code. I am getting a RunTime Error 1004 for Application.Workbooks.Open (StrFile). It seems like it is not able to find the file. The reason why I think that is because it is not showing the filepath but just the file in the directory shown below in the screenshot:

image of where error occurs

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

Use instead:

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