WD: How to Create a Template to Automatically Update All Fields

ID: Q122991

The information in this article applies to:

SUMMARY

This article contains instructions for creating a template that automatically updates all fields in a document, including fields contained in the header and footer areas. This article includes the following sections:

MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

   http://www.microsoft.com/supportnet/refguide/ 

Steps to Create the Macro

Create a macro to automatically update all fields by following these steps. Because the macro is called AutoNew and is stored in your template, this macro is available for all new documents you create based on your template.

1. From the File menu, choose New.

2. Choose the Template option and click OK to create a new template based

   on the Normal template.

3. On the Tools menu, choose Macro.

4. Type AutoNew in the Macro Name text box and click Create.

5. Using the following example, type the text that appears between the Sub

   MAIN line and second End Sub line.

    Sub MAIN
       Call Update
       ViewHeader
       Call Update
       GotoHeaderFooter
       Call Update
       CloseViewHeaderFooter
    End Sub

    Sub Update
      EditSelectAll
      UpdateFields
      CharLeft 1
    End Sub

5. Save and close the macro.

6. Save and close the template.

Steps to Insert the CreateDate Field

The CreateDate field inserts the date and/or time a document was first created. Using the template in which you created your macro, follow these steps:

1. On the View menu, choose Header And Footer.

2. Click the "Switch Between Header and Footer" button on the Header And

   Footer toolbar if you want to place the CreateDate field in the footer.

3. On the Insert menu, click Field.

4. In the Categories list, select Date And Time, and select CreateDate

   in the Field Names list.

5. Click Options.

6. Select the appropriate Date-Time format.

7. Click Add To Field.

8. Click OK twice.

Creating a Toolbar Button to Automatically Select Your Template

To add a button to your toolbar that automatically creates a new document based on your template, follow these steps:

 1. On the Tools menu, click Macro.

 2. In the Macro Name box, type a name such as "NewDocInMyTemp" (without
    the quotation marks).

 3. Click Record.

 4. Click Toolbars.

 5. In the Save Changes In list, choose Normal.dot.

 6. Drag the NewDocInMyTemp macro onto the appropriate toolbar.

 7. Select a toolbar button and click Assign.

 8. Click Close.

 9. Record the following steps:

    a. On the File menu, click New.

    b. Click to select your template and then click OK.

10. Click the Stop button on the Macro Recorder toolbar.

11. Save and close the template.

For information about how to do this in Word 97, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q159824
   TITLE     : How to Automatically Update Fields in a Document or Template

Additional query words: auto new open automatic template macro wordbasic
Keywords          : kbprg kbtemplate kbmacroexample winword macword word6 word7 word95 
Version           : WINDOWS: 6.0,6.0a,6.0c,7.0,7.0a ; MACINTOSH: 6.0,6.0.1,6.0.1a
Platform          : MACINTOSH WINDOWS
Issue type        : kbhowto

Last Reviewed: April 9, 1999