通过批处理文件或 vba 从 .xls 转换为 .xlsm 的方法?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7167207/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 13:52:37  来源:igfitidea点击:

Way to convert from .xls to .xlsm via a batch file or vba?

vbabatch-fileautomationxlsm

提问by BING

How to I automate the conversion of .xls workbooks to .xlsm?

如何自动将 .xls 工作簿转换为 .xlsm?

回答by JMax

You can try this code:

你可以试试这个代码:

Sub TrandformAllXLSFilesToXLSM()
Dim myPath As String

myPath = "C:\Excel\"
WorkFile = Dir(myPath & "*.xls")

Do While WorkFile <> ""
    If Right(WorkFile, 4) <> "xlsm" Then
        Workbooks.Open FileName:=myPath & WorkFile
        ActiveWorkbook.SaveAs FileName:= _
        myPath & WorkFile & "m", FileFormat:= _
        xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
        ActiveWorkbook.Close
     End If
     WorkFile = Dir()
Loop
End Sub

See this threadfor more info

有关更多信息,请参阅此线程