Saving a copy of the current workbbook as template

Guraknugen

New Member
Joined
Mar 15, 2017
Messages
36
I guess I need some help, I have tried "everything" (obviously not, but I reached EndOfIdeas).
I want to save the current workbook as a macro enabled template at some destination, but I don't want the template to then be my "current workbook".
Code:
ThisWorkbook.SaveCopyAs /Full/Path/To/Template.xltm, FileFormat:=xlOpenXMLTemplateMacroEnabled
The problem is that ThisWorkbook.SaveCopyAs doesn't support FileFormat.

Any suggestions for workarounds?
 
Last edited:

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
SaveCopyAs does not have any of the attributes of SaveAs that allows you to specify file type – It just makes a copy of your current workbook with your chosen file name.

A solution I provided to another here with similar requirement was to create code that would:
- Save active workbook
- Use SaveAs to save a copy with the specified filename & file type
- Re-Open the saved workbook
- Close the copy workbook.

Try this update to code I suggested & see if it helps you.

Place in a STANDARD module

Code:
 Sub SaveCopyAs(ByVal FileName As String, ByVal FileFormat As XlFileFormat, Optional ByVal wb As Workbook)    
   'dmt32 jan 2018
    Dim ActiveFile As String
    
    On Error GoTo myerror
    If wb Is Nothing Then Set wb = ThisWorkbook
    If wb.Path = "" Then Err.Raise 76
    
    With Application
        .ScreenUpdating = False: .EnableEvents = False: .DisplayAlerts = False
    End With
    
    With wb
        .Save
        ActiveFile = .FullName
        .SaveAs FileName:=FileName, FileFormat:=FileFormat
    End With


    
    Workbooks.Open ActiveFile
    
    wb.Close False
    
myerror:
    With Application
        .ScreenUpdating = True: .EnableEvents = True: .DisplayAlerts = True
    End With
    If Err > 0 Then MsgBox (Error(Err)), 48, "Error"
End Sub


And call it in similar way to your published requirement

Code:
 SaveCopyAs "C:\Full\Path\To\TemplateName", FileFormat:=xlOpenXMLTemplateMacroEnabled


Hope Helpful

Dave
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,195
Members
452,616
Latest member
intern444

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top