View Single Post
 
Old 07-02-2022, 10:39 AM
Charles Kenyon Charles Kenyon is offline Windows 11 Office 2021
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,473
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

An AutoNew macro or the corresponding Document_New procedure go in the template.

Run a macro automatically when a document is created, opened or closed
Assuming that the Document_New procedure is in the ThisDocument module of your template...
Code:
Sub Document_New()
' Charles Kenyon 2022-07-02
    '   Written by Charles Kyle Kenyon 2 July 2022
    '   assistance from Jezebel
    '   All Story Field Updater - AutoText fields - then unlinks
    Dim oField As Field
    Dim oStory As range
    '    On Error Resume Next
    For Each oStory In ActiveDocument.StoryRanges
        ' This goes into headers and footers as well as the regular document
        Do
            For Each oField In oStory.Fields
                If oField.Type = wdFieldAutoText Then
                    oField.Update
                    oField.Unlink ' this will no longer be a field
                End If
            Next oField
            Set oStory = oStory.NextStoryRange
        Loop Until oStory Is Nothing
    Next oStory
    Set oStory = Nothing
    On Error GoTo -1

End Sub
This macro will update all AutoText fields in a new document created from the template and then remove the field leaving the results. If documents are going to someone else, you do not want these fields in the document, you want what they produce. This could be restricted to headers or footers but I know of no reason to do so.
Reply With Quote