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

ID: Q122991


The information in this article applies to:
  • Microsoft Word for Windows, versions 6.0, 6.0a, 6.0c
  • Microsoft Word for Windows 95, versions 7.0, 7.0a
  • Microsoft Word for the Macintosh, versions 6.0, 6.0.1, 6.0.1a


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:

  • Steps to Create the Macro


  • Steps to Insert the CreateDate Field


  • Creating a Toolbar Button to Automatically Select Your Template



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.


  6. 
        Sub MAIN
           Call Update
           ViewHeader
           Call Update
           GotoHeaderFooter
           Call Update
           CloseViewHeaderFooter
        End Sub
    
        Sub Update
          EditSelectAll
          UpdateFields
          CharLeft 1
        End Sub 
  7. Save and close the macro.


  8. 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.


  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:


    1. On the File menu, click New.


    2. 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:
Q159824 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 : MACINTOSH:6.0,6.0.1,6.0.1a; WINDOWS:6.0,6.0a,6.0c,7.0,7.0a
Platform : MACINTOSH WINDOWS
Issue type : kbhowto


Last Reviewed: September 23, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.