From: Rob M on 8 Mar 2010 17:15 Hi, Can anyone tell me how to use VBA to update all docvariable fields in all active documents? I know how to update a single document, but I'm having trouble cycling through all active documents. Thank you, Rob
From: Greg Maxey on 8 Mar 2010 17:29 Probably a bit of overkill as this would update "all" fields (not just docVariables fields). Sub ScratchMaco() Dim oDoc As Word.Document For Each oDoc In Documents UpdateFields oDoc Next oDoc End Sub Sub UpdateFields(Doc As Word.Document) Dim pRange As Word.Range Dim oShp As Shape Dim iLink As Long Dim TOC As TableOfContents Dim TOF As TableOfFigures Dim TOA As TableOfAuthorities Dim pAlerts As String pAlerts = Application.DisplayAlerts Application.DisplayAlerts = wdAlertsNone iLink = Doc.Sections(1).Headers(1).Range.StoryType For Each pRange In Doc.StoryRanges Do pRange.Fields.Update Select Case pRange.StoryType Case 6, 7, 8, 9, 10, 11 If pRange.ShapeRange.Count > 0 Then For Each oShp In pRange.ShapeRange If oShp.TextFrame.HasText Then oShp.TextFrame.TextRange.Fields.Update End If Next oShp End If End Select Set pRange = pRange.NextStoryRange Loop Until pRange Is Nothing Next Application.DisplayAlerts = pAlerts For Each TOC In Doc.TablesOfContents TOC.Update Next TOC For Each TOA In Doc.TablesOfAuthorities TOA.Update Next TOA For Each TOF In Doc.TablesOfFigures TOF.Update Next TOF End Sub "Rob M" <rjm972(a)gmail.com> wrote in message news:ed694fba-dba5-4b70-810b-a3e71b63815b(a)j27g2000yqn.googlegroups.com... > Hi, > > Can anyone tell me how to use VBA to update all docvariable fields in > all active documents? I know how to update a single document, but I'm > having trouble cycling through all active documents. > > Thank you, > Rob
From: Doug Robbins - Word MVP on 8 Mar 2010 18:35 A somewhat shorter macro If Options.UpdateFieldsAtPrint = False Then Options.UpdateFieldsAtPrint = True With ActiveDocument .PrintPreview .ClosePrintPreview End With Options.UpdateFieldsAtPrint = False Else With ActiveDocument .PrintPreview .ClosePrintPreview End With End If -- Hope this helps. Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis. Doug Robbins - Word MVP, originally posted via msnews.microsoft.com "Rob M" <rjm972(a)gmail.com> wrote in message news:ed694fba-dba5-4b70-810b-a3e71b63815b(a)j27g2000yqn.googlegroups.com... > Hi, > > Can anyone tell me how to use VBA to update all docvariable fields in > all active documents? I know how to update a single document, but I'm > having trouble cycling through all active documents. > > Thank you, > Rob
From: Rob M on 9 Mar 2010 09:30 Thank you both for the replies! Very helpful, and I appreciate it. Cheers, Rob
|
Pages: 1 Prev: Create DocumentPropertiesPanel in Word 2003 Next: Calculate form fields... |