在一個文件夾中有數(shù)百個.txt文件,想將其另存為.xls文件,保存時文件名與原文件名相同;且將內(nèi)容按空格分列(.txt文件中格式相同),使用VBA可以實現(xiàn)該功能,代碼如下:
Dim Fso, Fl
Set Fso = CreateObject("Scripting.FileSystemObject")
For Each Fl In Fso.getfolder(ThisWorkbook.Path & "").Files
If Fl.Name <> ThisWorkbook.Name Then
Workbooks.OpenText (Fl)
With ActiveWorkbook
.SaveAs ThisWorkbook.Path & "" & Fl.Name & ".xls"