Hi All,

I have code written to open a single .txt file (attached), format it using comma as delimiter and save it as either .xls or .xlsx file.

I need to open multiple files like this. Right now I go back to vba editor, copy the below code, paste it multiple times and only change the name of the .txt file.

Could anyone help me how I can do the above operation using a simpler code?

Sub import()
'
' import Macro

    fpath = "D:\Desktop\FCST\"
    
    Workbooks.OpenText Filename:= _
        fpath & "\FCST A.txt", Origin:=437, StartRow:=1 _
        , DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
        ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, Comma:=True, _
        Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 1), Array( _
        3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), Array(9, 1), Array(10 _
        , 1), Array(11, 1), Array(12, 1), Array(13, 1), Array(14, 1), Array(15, 1), Array(16, 1), _
        Array(17, 1), Array(18, 1), Array(19, 1), Array(20, 1), Array(21, 1), Array(22, 1), Array( _
        23, 1), Array(24, 1), Array(25, 1), Array(26, 1), Array(27, 1), Array(28, 1), Array(29, 1), _
        Array(30, 1), Array(31, 1), Array(32, 1), Array(33, 1), Array(34, 1)), _
        TrailingMinusNumbers:=True
    ActiveWorkbook.SaveAs Filename:= _
        fpath & "FCST A.xlsx", FileFormat:=xlOpenXMLWorkbook