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:
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
改用:
Application.Workbooks.Open(FilePath & strFile)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.