The below code works great... for ONE file. But the files are from 1800.txt to 2000.txt. How do I insert this into a loop so I don't have to enter a filename? It just opens every txt file in that folder, parses it, then saves it as the same name but as an xlxs file?
Again, C:\temp\ contains 200 txt files. I need to import and delimit each one, then save it as the same name but as an xlsx instead. Ex. 1800.txt should become 1800.xlsx. The code below works for that one file. I'd have to edit it for every single file in that folder and wouldn't end up saving me a minute of time.
Thanks in advance!
--------------------------------------------------
Sub Import01()
'
' Import01 Macro
'
' Keyboard Shortcut: Ctrl+Shift+I
'
Workbooks.OpenText Filename:= _
"C:\temp\1800.txt", _
Origin:=xlWindows, StartRow:=475, DataType:=xlFixedWidth, FieldInfo:= _
Array(Array(0, 1), Array(4, 1), Array(32, 1), Array(44, 1), Array(54, 1)), _
TrailingMinusNumbers:=True
Range("A1").Select
Columns("E:E").EntireColumn.AutoFit
Columns("D:D").EntireColumn.AutoFit
Columns("C:C").EntireColumn.AutoFit
Columns("B:B").EntireColumn.AutoFit
Columns("A:A").EntireColumn.AutoFit
ActiveWorkbook.SaveAs Filename:= _
"C:\temp\1800.xlsx" _
, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
End Sub
Again, C:\temp\ contains 200 txt files. I need to import and delimit each one, then save it as the same name but as an xlsx instead. Ex. 1800.txt should become 1800.xlsx. The code below works for that one file. I'd have to edit it for every single file in that folder and wouldn't end up saving me a minute of time.
Thanks in advance!
--------------------------------------------------
Sub Import01()
'
' Import01 Macro
'
' Keyboard Shortcut: Ctrl+Shift+I
'
Workbooks.OpenText Filename:= _
"C:\temp\1800.txt", _
Origin:=xlWindows, StartRow:=475, DataType:=xlFixedWidth, FieldInfo:= _
Array(Array(0, 1), Array(4, 1), Array(32, 1), Array(44, 1), Array(54, 1)), _
TrailingMinusNumbers:=True
Range("A1").Select
Columns("E:E").EntireColumn.AutoFit
Columns("D:D").EntireColumn.AutoFit
Columns("C:C").EntireColumn.AutoFit
Columns("B:B").EntireColumn.AutoFit
Columns("A:A").EntireColumn.AutoFit
ActiveWorkbook.SaveAs Filename:= _
"C:\temp\1800.xlsx" _
, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
End Sub