0

So I found code on here to convert from .xls to .xlsm, but I would like to convert from .xlsx to .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
  • 36,585
  • 5
  • 27
  • 39

1 Answers1

1

As Compo said, not close to a batch file or vbs at all.

Added this as a module to mine and and tested it in this particular path. Being a NEWB myself, I am sure there is a cleaner way to do this.

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
Bryant J
  • 28
  • 6
  • That helped me out! I only tagged the batch file because the previous link tagged it, so that was my bad. Keep up the good work. – HopDevvil814 Sep 24 '20 at 14:40