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

时间:2011-08-23 20:33:37

标签: vba batch-file automation xlsm

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

1 个答案:

答案 0 :(得分:3)

您可以尝试以下代码:

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

有关详细信息,请参阅此thread