Good Afternoon All,
I recently received help on a macro I am creating to run a loop through all files in a set folder. (seen here:
http://www.excelforum.com/excel-prog...ml#post3471431)
A very helpful member has assisted me in my journey of completing said task but I am faced with an error of "Run-time error '1004': Excel cannot find the text file to refresh this external data range" and then proceeds to end up at the line:
.Refresh BackgroundQuery:=False
Its not producing an output file for the first one before looping through and I cannot figure out how to resolve the error.
Any suggestions or reference material would be greatly appreciated!
Sub Import_Many_Files()
Dim Input_File As String
Dim Input_File_Name As String
Input_File = Dir("C:\Path\*.pch")
Do Until Dir = ""
Call Import_PCH_File(Input_File)
Input_File = Dir
Loop
End Sub
Function Import_PCH_File(Input_File As String)
Input_File_Name = CStr(Input_File)
If Right(Input_File_Name, 1) <> "\" Then Input_File_Name = Input_File_Name & "\"
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & Input_File, _
Destination:=Range("$A$1"))
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlFixedWidth
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1)
.TextFileFixedColumnWidths = Array(16, 2, 20, 16, 20)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Application.CalculateFull
ActiveWorkbook.SaveAs Filename:=Left(Input_File_Name, InStrRev(Input_File_Name, ".")) & "xlsm", FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
ActiveWorkbook.Close
End Function
Bookmarks