Dim app, fso, file, fName, wb, dir
dir = "D:TA"
dirsave = "D:TAXLS"
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文件,但它抛出错误
错误:工作簿类的另存为方法失败。
我该如何解决它?提前致谢
看起来脚本中缺少"\"。它可能应该是:
dirsave = "D:TAXLS"
或者,它也可以是:
app.ActiveWorkbook.SaveAs dirsave & "" & fName & ".xls", 43
任何一种选择都应该有效,尽管我更喜欢选项一,因为它更整洁