Here are a macro that creates a new document based on a template and the function that helps set the path to find the template. (You can hard code the path instead, if you want. This one gets templates from my Workgroup Templates folder.)
Code:
Sub KenyonBill()
'
' KenyonBill Macro
' Macro written 7/5/02 by Charles Kyle Kenyon
' "&chr(10)&"New letter based on Kenyon Letterhead form
' Calls WorkgroupPath Function (below)
'
Dim sTemplatesPath As String
sTemplatesPath = WorkGroupPath & "Menus\Office Forms"
Documents.Add Template:= _
sTemplatesPath & "Kenyon Bill Form.dotm" _
, NewTemplate:=False
End Sub
Code:
Function WorkGroupPath() As String
' Written by Charles Kenyon
' February 28, 2003
'
' Used by templates menus to set location of templates.
' Returns workgroup tempates path with "" at the end.
'
' This is needed because if the folder is a network drive rather
' than a folder, it will have the "" already. If it is a folder,
' it will not have the backslash. This function gives a string
' with the backslash in either case.
'
WorkGroupPath = Application.Options.DefaultFilePath(wdWorkgroupTemplatesPath)
If Right(WorkGroupPath, 1) <> "" Then
WorkGroupPath = WorkGroupPath & ""
End If
End Function
If running from a macrobutton field, include the following statement in the macro to create the document. Otherwise, the field remains selected.
See also
Making MacroButtonFields respond to a single click
You need to have the following command in an AutoMacro. This can be in your normal template or a document template. Without this, it takes a double-click to run the macro.
Code:
Options.ButtonFieldClicks = 1
Example for the normal template:
Code:
Sub AutoExec({)
Options.ButtonFieldClicks = 1
End Sub
If you have a number of templates you want to create documents from, consider, instead of macrobutton fields, a custom Ribbon tab with the macros or adding them to your QAT.
Modifying the Quick Access Toolbar (QAT) in Microsoft Word