从 .xlsx 转换为 .xlsm 的方法?

Way to convert from .xlsx to .xlsm?

所以我在这里找到了从 .xls 转换为 .xlsm 的代码,但我想从 .xlsx 转换为 .xlsm

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

Here is the link

正如 Compo 所说,根本不接近批处理文件或 vbs。

将其作为一个模块添加到我的矿井中,并在此特定路径中对其进行了测试。作为我自己的 NEWB,我相信有一种更简洁的方法可以做到这一点。

Sub XLSX2XLSM()
Dim myPath As String

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

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