需要VBS代码来保存xlsm

时间:2021-05-15 07:30:11

I have tried so many websites and combinations but I can not create a VBS script to open my CsV file and then save it as a Xlsm file. I did get it to rename the file but the renamed file was deemed corrupt and would not open. In Excel you can open a CSV and do a save as Xlsm and it works. I want to automate this process with the sccript below. This is Excel 2013. Option Explicit

我尝试了很多网站和组合,但是我不能创建VBS脚本来打开我的CsV文件,然后将它保存为Xlsm文件。我确实让它重命名文件,但重命名的文件被认为是损坏的,不会打开。在Excel中,你可以打开CSV并保存为Xlsm。我想用下面的sccript来自动化这个过程。这是Excel 2013。选项显式

Dim xlApp, xlBook

Set xlApp = CreateObject("Excel.Application")
xlApp.DisplayAlerts = False
Set xlBook = xlApp.Workbooks.Open("c:\1Datadump\datadump.csv")
xlApp.Application.Visible = True


ActiveWorkbook.SaveAs Filename:="C:\1Datadump\datadump.xlsm"
xlApp.Workbooks.close
xlApp.Application.Quit

Thank you for any suggestions.

谢谢你的建议。

2 个解决方案

#1


1  

Read here or here that/why

读这里或这里的那/为什么

ActiveWorkbook.SaveAs Filename:="C:\1Datadump\datadump.xlsm"

(:=, named parameter) is not valid VBScript.

(:=,命名参数)不是有效的VBScript。

#2


0  

You need to specify the FileFormat. You'll also need to qualify your workbook reference:

您需要指定FileFormat。您还需要限定您的工作簿参考:

If you want to save the ActiveWorkbook then use Application.ActiveWorkbook:

如果您想保存ActiveWorkbook,请使用Application.ActiveWorkbook:

Const xlOpenXMLWorkbookMacroEnabled = 52
xlApp.ActiveWorkbook.SaveAs "C:\1Datadump\datadump.xlsm", xlOpenXMLWorkbookMacroEnabled

But since you already have a refernce to the workbook; I'd use:

但是既然你已经有了参考书;我使用:

Const xlOpenXMLWorkbookMacroEnabled = 52
xlBook.SaveAs "C:\1Datadump\datadump.xlsm", xlOpenXMLWorkbookMacroEnabled

#1


1  

Read here or here that/why

读这里或这里的那/为什么

ActiveWorkbook.SaveAs Filename:="C:\1Datadump\datadump.xlsm"

(:=, named parameter) is not valid VBScript.

(:=,命名参数)不是有效的VBScript。

#2


0  

You need to specify the FileFormat. You'll also need to qualify your workbook reference:

您需要指定FileFormat。您还需要限定您的工作簿参考:

If you want to save the ActiveWorkbook then use Application.ActiveWorkbook:

如果您想保存ActiveWorkbook,请使用Application.ActiveWorkbook:

Const xlOpenXMLWorkbookMacroEnabled = 52
xlApp.ActiveWorkbook.SaveAs "C:\1Datadump\datadump.xlsm", xlOpenXMLWorkbookMacroEnabled

But since you already have a refernce to the workbook; I'd use:

但是既然你已经有了参考书;我使用:

Const xlOpenXMLWorkbookMacroEnabled = 52
xlBook.SaveAs "C:\1Datadump\datadump.xlsm", xlOpenXMLWorkbookMacroEnabled