Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update reference fields via VBA?

Status
Not open for further replies.

GrodanBoll

Programmer
Mar 6, 2002
45
0
0
ZA
Hi

In my template I reference custom propertie fields (DOCPROPERTY) via the reference fields.
When I close my user form that I use to populate al the custom properties I do a print preview in my code to update all the reference fields.

The reference fields in the headers and footer gets updated but not the fields in the document body (which are copies of the fields in the header/footer).

I can manually update the fields in the body so the code shoud be righht?

Exampel code in the referense field:
Code:
    {DOCPROPERTY  _gen_document_project_name  \* MERGEFORMAT}

Code to update the fields via print preview:
Code:
    'Updates the fields by going to Print Preview and back to print View.
    ActiveDocument.PrintPreview
    If ActiveWindow.View.SplitSpecial = wdPaneNone Then
        ActiveWindow.ActivePane.View.Type = wdPrintView
    Else
        ActiveWindow.View.Type = wdPrintView
    End If

Why will not the fields in the document body update?
Will be greatful for any help. =]

Thanx
Grodan
 
Used
Code:
'
'Updates all fields in the document.
'From: [URL unfurl="true"]http://www.gmayor.com/installing_macro.htm[/URL]
'
Sub UpdateAll()
    
    Dim oStory As Range
        
        For Each oStory In ActiveDocument.StoryRanges
        
            oStory.Fields.Update
            
            If oStory.StoryType <> wdMainTextStory Then
                
                While Not (oStory.NextStoryRange Is Nothing)
                
                    Set oStory = oStory.NextStoryRange
                    oStory.Fields.Update
                
                Wend
            
            End If
            
        Next oStory
    
    Set oStory = Nothing


End Sub
and it seems to work like a charm. =]

Thread solved.

Thanx and bye for now
/Grodan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top