【发布时间】:2019-12-06 11:03:15
【问题描述】:
Dim app, fso, file, fName, wb, dir
dir = "D:\TA"
dirsave = "D:\TA\XLS"
Set app = CreateObject("Excel.Application")
Set fso = CreateObject("Scripting.FileSystemObject")
For Each file In fso.GetFolder(dir).Files
If LCase(fso.GetExtensionName(file)) = "csv" Then
fName = fso.GetBaseName(file)
Set wb = app.Workbooks.Open(file)
app.Application.Visible = True
app.Application.DisplayAlerts = False
app.ActiveWorkbook.SaveAs dirsave & fName & ".xls", 43
app.ActiveWorkbook.Close
app.Application.DisplayAlerts = True
app.Application.Quit
End if
Next
Set fso = Nothing
Set wb = Nothing
Set app = Nothing
wScript.Quit
我正在使用上面的 VB 脚本打开 csv 文件并将其保存为 xls 文件,但它会引发错误
错误:Workbook 类的 SaveAs 方法失败。
我该如何解决? 提前致谢
【问题讨论】: