Save every worksheet as individual workbook (file format xlsm)

Dear Experts:

Below macro saves every worksheet to a new workbook. It is running fine. The only thing I cannot change is the file format to which the individal worksheets are to be saved. Below code only saves them as .xlsx. I would like to get them saved as "xlsm".

How is this done?

Help is much appreciated. Thank you very much in advance.

Regards, Andreas
Sub ExportToWorkbooks_2()
    Dim NewBook As Workbook, OldBook As Workbook, sh As Worksheet
     
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
     
    ' xlWorkbookDefault (.xlsx)
     
    Set OldBook = ThisWorkbook
     
    For Each sh In OldBook.Worksheets
        If sh.Visible = True Then
            sh.Copy
            ActiveWorkbook.SaveAs Filename:=OldBook.Path & "\" & sh.Name & "VALUES", FileFormat:=xlWorkbookDefault
            ActiveWorkbook.Close
        End If
    Next
     
    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
     
End Sub

Open in new window

Andreas HermleTeam leaderAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nutschCommented:
You have to change the fileformat to FileFormat:=xlOpenXMLWorkbookMacroEnabled

The best way to see code often is to record a macro with what you want to do and see the resulting code.

Thomas

Sub ExportToWorkbooks_2()
    Dim NewBook As Workbook, OldBook As Workbook, sh As Worksheet
     
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
     
    ' xlWorkbookDefault (.xlsx)
     
    Set OldBook = ThisWorkbook
     
    For Each sh In OldBook.Worksheets
        If sh.Visible = True Then
            sh.Copy
            ActiveWorkbook.SaveAs Filename:=OldBook.Path & "\" & sh.Name & "VALUES", FileFormat:=xlOpenXMLWorkbookMacroEnabled
            ActiveWorkbook.Close
        End If
    Next
     
    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
     
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Andreas HermleTeam leaderAuthor Commented:
ok, thank you very much for your professional help. Regards, Andreas
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.