Visual Basic (VB and VBA)

Copyright 1999-2001 Christopher Greaves. All rights reserved.
Home Page and email to [email protected]
If in doubt, record a macro and inspect the entrails!

 

 

Please read the DISCLAIMER.

Here is an INDEX to all the procedures.

You will probably need one copy of my GLOBAL DECLARATIONS.



Public Sub udfUpdateAllFields()
' Procedure :   UpdateAllFields
' Description:  Update all fields in a document.
' Copyright: Chris Greaves Inc.
' Inputs:       None
' Returns:      None
' Assumes:      Nothing
' Side Effects: None
' Tested:       By a call from the user.
  Dim oStory As Range
  Dim sSection As Section
  Dim hHeader As HeaderFooter
  Dim shpShape As Shape
  For Each oStory In ActiveDocument.StoryRanges
    oStory.Fields.Update
  Next oStory
    ' Work around VBA bug: StoryRanges does not
    ' include textboxes in header/footer
    ' Ref: KB article Q212564
  ' Loop through each section in the document.
  For Each sSection In ActiveDocument.Sections
     ' Loop through each header in each section.
     For Each hHeader In sSection.Headers
        ' If the header is the Primary header.
        If hHeader.Index = wdHeaderFooterPrimary Then
           ' Loop through each Shape object in the header.
           For Each shpShape In hHeader.Shapes
              ' If the shapetype is a text box.
              If shpShape.Type = msoTextBox Then
                 ' Display the text in each textbox found.
                 shpShape.TextFrame.TextRange.Fields.Update
              End If
           Next shpShape
        End If
     Next hHeader
  Next sSection
End Sub

We all knew nothing when we started …
Home Page and Contact Information
Send email to [email protected].
This page was last updated Thursday, November 15, 2001

 

 

Hosted by www.Geocities.ws

1

Visual Basic (VB and VBA)

Copyright 1999-2001 Christopher Greaves. All rights reserved.
Home Page and email to [email protected]
If in doubt, record a macro and inspect the entrails!

 

 

Please read the DISCLAIMER.

Here is an INDEX to all the procedures.

You will probably need one copy of my GLOBAL DECLARATIONS.

Public Sub udfUpdateAllFields()
' Procedure :   UpdateAllFields
' Description:  Update all fields in a document.
' Copyright: Chris Greaves Inc.
' Inputs:       None
' Returns:      None
' Assumes:      Nothing
' Side Effects: None
' Tested:       By a call from the user.
  Dim oStory As Range
  Dim sSection As Section
  Dim hHeader As HeaderFooter
  Dim shpShape As Shape
  For Each oStory In ActiveDocument.StoryRanges
    oStory.Fields.Update
  Next oStory
    ' Work around VBA bug: StoryRanges does not
    ' include textboxes in header/footer
    ' Ref: KB article Q212564
  ' Loop through each section in the document.
  For Each sSection In ActiveDocument.Sections
     ' Loop through each header in each section.
     For Each hHeader In sSection.Headers
        ' If the header is the Primary header.
        If hHeader.Index = wdHeaderFooterPrimary Then
           ' Loop through each Shape object in the header.
           For Each shpShape In hHeader.Shapes
              ' If the shapetype is a text box.
              If shpShape.Type = msoTextBox Then
                 ' Display the text in each textbox found.
                 shpShape.TextFrame.TextRange.Fields.Update
              End If
           Next shpShape
        End If
     Next hHeader
  Next sSection
End Sub

We all knew nothing when we started …
Home Page and Contact Information
Send email to [email protected].
This page was last updated Thursday, November 15, 2001

 

 

Hosted by www.Geocities.ws

1