Share via

Update all frame fields content with VBA

Anonymous
2021-10-10T17:39:13+00:00

I'm able to update all content including headers with

ActiveDocument.Fields.Update  
For Each header In ActiveDocument.Sections(ActiveDocument.Sections.Count).Headers()  
    header.Range.Fields.Update  
Next

But how do I update content in frames?

Microsoft 365 and Office | Word | For business | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Jay Freedman 207.7K Reputation points Volunteer Moderator
2021-10-10T19:01:48+00:00

For frames within the document's main StoryRange, you can just use

    Dim f As Frame 

    For Each f In ActiveDocument.Frames 

        f.Range.Fields.Update 

    Next f 

If there are frames anchored in headers, though, you'll have to handle those separately. This is similar to how you handled fields in the headers themselves.

    Dim f As Frame 

    Dim h As HeaderFooter 

    For Each f In ActiveDocument.Frames 

        f.Range.Fields.Update 

    Next f 

    For Each h In ActiveDocument.Sections.Last.Headers 

        For Each f In h.Range.Frames 

            f.Range.Fields.Update 

        Next f 

    Next h 

Gratuitous hint: Sections.Last is the same as Sections(ActiveDocument.Sections.Count).

Was this answer helpful?

2 people found this answer helpful.
0 comments No comments

0 additional answers

Sort by: Most helpful