Peter Wirdemo
Peter Wirdemo

Reputation: 526

Word 2013 VBA - Save template including macro modules

I have an macro-enabled template. One function is saving the current document (based on the template) as another macro-enabled template. Code:

Private Sub cmdSaveAsTemplate_Click()

    Dim choice As Integer
    Dim dia As FileDialog

    Set dia = Application.FileDialog(msoFileDialogSaveAs)
    dia.FilterIndex = 5
    dia.InitialFileName = "TEMPLATE DealDoc"

    choice = dia.Show
    If choice <> 0 Then
        dia.Execute

    End If

End Sub

This code works fine except that the saved "copy" does not contain the macros and forms.

I want the saved template to contain the makro modules, forms and the code inside "ThisDocument".

Upvotes: 0

Views: 217

Answers (1)

Cindy Meister
Cindy Meister

Reputation: 25673

It's not possible to save the macros in an attached template into a document created from the template using SaveAs, not even when saving as file type docm.

The only way would be to create the new file as a new template, right from the start:

Documents.Add Template:=pathNameToTemplate, NewTemplate:=True

Upvotes: 1

Related Questions