Create macro-enabled templates

You can create your own macro-enabled templates to set default values and to perform merge and other important functions in WorkZone for Word.

To use macro-enabled templates, you need to enable macros first.


Create a macro-enabled template

  1. Open a new Microsoft Word document.
  2. On the Developer tab in the Code group, click Visual Basic.
  3. -Or-

    Press Alt+F11.

    A new Visual Basic document opens.


Example of an advanced document template

In this example, we are creating a macro-enabled template for a standard letter that prompts the user to select a case for a document and then recipients. Finally, it merges all the information into the document, after which the user can write the content of the letter.

Public WithEvents App As Word.Application
     Public IsScriptExecuted As Boolean
     Private Sub App_DocumentChange()
        If Not IsScriptExecuted Then
        	Dim addIn As COMAddIn
        	Set addIn = Application.COMAddIns("Scanjour.Office.WordAddIn")
		IsScriptExecuted = True
        		If Not addIn.Object.IsMergedDocument Then
        			' <- Place your code here (START)
        			addIn.Object.SetDocumentMetadata "title", "Hello"
        			addIn.Object.SetDocumentMetadata "record_type", "NT"
        			addIn.Object.SetDocumentMetadata "record_grp", "INF"
        			addIn.Object.RegistrationPaneVisible = True
        			addIn.Object.ShowDocumentRecipientsDialog
        			addIn.Object.Merge
        			' <- Place your code here (END)
       		 End If
        End If  
     End Sub


Display the Developer tab

By default, the Developer tab is not displayed in the ribbon. To display it, you need to perform the following steps:

  1. Start Microsoft Word.
  2. On the File tab, select Options. The Word Options dialog box displays.
  3. In the categories pane, select Customize Ribbon.
  4. In the Main Tabs list, select the Developer check box.
  5. Click OK.
  6. On the Developer tab that has just appeared, click Visual Basic.
  7. In the Project pane, right-click the Microsoft Word Objects folder, and select Insert > Class Module. A new Class1 class is added to the project tree.
  8. Rename the Class1 module to ThisApplication.
  1. In the Project pane, double-click ThisApplication in the project tree. A new ThisApplication document opens.
  2. Enter a code in the ThisApplication document.
  3. Right-click your code project. Then click the Insert menu, and click Module.
  4. In the Properties pane (lower left corner of screen), click the Name field, and type AppEventHandler.
  5. In the Code pane (right side of screen), type the following:
    Dim wordApp As New ThisApplication.
Sub AutoNew()
        Set wordApp.App = Word.Application
        wordApp.IsScriptExecuted = False
End Sub
  1. Save the document template in .dotm format.
  2. To use your template, just copy it to a target machine, and open it. As a result, a new document will be created based on your template (that is, with your template script executed).

Notes:  

  • To modify your template, right-click it from Windows Explorer, and select Edit from a context menu.
  • You can have more than one macro template, however only one template will be used at the same time.