VBA把记事本保存成为工作薄
在一个文件夹中有数百个.txt文件,想将其另存为.xls文件,保存时文件名与原文件名相同;且将内容按空格分列(.txt文件中格式相同),使用VBA可以实现该功能,代码如下:
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"
.Close 0
End With
End If
Next
赞 (0)