当前位置:网站首页>Batch convert txt to excel format

Batch convert txt to excel format

2022-07-05 07:15:00 RS&Hydrology

What you want to achieve : The batch will txt Convert to corresponding Excel Format ( One txt The file corresponds to a Excel file ).

1. Use existing tools ( It is suitable for the situation of small amount of data )
It can be converted online directly :https://anyconv.com/txt-to-xlsx-converter/
Pro testing can be used , But download one by one .

2. utilize VBA

Sub txt2excel()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Dim txt, fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogFilePicker)
     With fd
        .AllowMultiSelect = True
         If .Show = -1 Then
             For Each txt In .SelectedItems
                 Workbooks.OpenText Filename:=txt, Origin:=936, DataType:=xlDelimited, Semicolon:=False, Comma:=True, Space:=False, Other:=False, Tab:=True
                 Range("a:u").NumberFormatLocal = "@"
                 ActiveWorkbook.SaveAs Filename:=Mid(txt, 1, Len(txt) - 4) & ".xls", FileFormat:=xlExcel8
                 'ActiveWorkbook.SaveAs Filename:=Mid(txt, 1, Len(txt) - 4), FileFormat:=xlExcel8
                 ActiveWorkbook.Close True
             Next
         Else
             Exit Sub
         End If
     End With
End Sub
原网站

版权声明
本文为[RS&Hydrology]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140559171621.html