Update all docvariables in all active documents

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
0
Rob
3/8/2010 10:15:44 PM
word.vba.general 1023 articles. 1 followers. Follow

3 Replies
2894 Views

Similar Articles

[PageSpeed] 3

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@gmail.com> wrote in message 
news:ed694fba-dba5-4b70-810b-a3e71b63815b@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 


0
Greg
3/8/2010 10:29:47 PM
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@gmail.com> wrote in message 
news:ed694fba-dba5-4b70-810b-a3e71b63815b@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 

0
Doug
3/8/2010 11:35:47 PM
Thank you both for the replies!  Very helpful, and I appreciate it.

Cheers,
Rob
0
Rob
3/9/2010 2:30:53 PM
Reply:

Similar Artilces:

Activating ActiveSync under control
Hi all, just to avoid to leave free access to the storage area of the board, is it possible to run ActiveSync support under some restricted situations? Example: normal start of the board -> ActiveSync not activated Start with a key pressed -> ActiveSync activated .... or something similar How can i do it? In the board i have a C startup application that could do that ... -- SteM Yes. You will need to disable starting of Repllog.exe in the database. Then just run repllog.exe when you need to connect. -- Bruce Eitman (eMVP) Senior Engineer Bruce.Eitman AT Eurote...

Windows Update Failures
Running Windows XP Pro, SP3 and Office 2007 Ultimate. I have five updates that will not install. I am getting three different error codes. I have searched the web and this message board for a solution to no avail. I have tried installing each one individually, in groups (e.g. Office 2007 group and Windows XP group), as well as trying to install all five together. Regardless, I always get the same error codes on each of these. Below are the updates and the error codes received for each one. Appreciate any help to get over this issue. Windows XP - Microsoft .NET Framewo...

Why does a graphic or print multiple times in the same document?
When I print from publisher to my Canon color copier,graphics appear multiple times in the same document. This could be many things- Temp files need cleaning A simple restart of cpu & printer A bad printer driver Check those first. "Carla" wrote: > When I print from publisher to my Canon color copier,graphics appear multiple > times in the same document. Carla wrote: || When I print from publisher to my Canon color copier,graphics appear || multiple times in the same document. Carla, check out the following kb article. This is actually a known bug that affects the e...

How do I change a flyer (word document) into a picture?
I created a flyer and I want to change it into a picture so I can upload it as a picture on facebook. How do I change the 2007 word document into a picture? This newsgroup is for Microsoft Project, a planning and scheduling application. Questions about Microsoft Word, should be published to the Word newsgroup. To address your question, try using File/Save As... and select type PDF. If the document must be an image format (such as BMP, JPG, GIG, etc) you will probably need some screen capture software such as Snag-It or the clipping tool available with Windows Vista and later. ...

CD/DVD can't "see" CDs after Windows Vista update (KB973917)
Ever since this update installed, my CD/DVD drive does not see any CD or DVD I put in the drive. I have looked for an updated driver and have the most recent driver. I have uninstalled the driver and reinstalled it, both with and without shutting down the laptop and starting it up again. Device Manager says the device is working properly, which it clearly isn't. I am wondering if I should uninstall the update. Lisa This sometimes happens Go into the Registry and search for Upper and Lower Filters. When found delete both of them. Close out and Save and then reboot. ...

How to change Marketing list member "All members" to "Active membe
How to change Marketing list member "All members" to "Active members" in CRM 4.0? Any help is appreciated. I have used the following code giving object required error code: /************************************************************** * Change the default view of the Marketing List Members (Account) **************************************************************/ if (crmForm.all.createdfromcode.DataValue == 1) { if (crmForm.FormType != 1 && crmForm.FormType != 5 && crmForm.FormType != 6) { /************************************************************** ...

Set Number of Previous Documents under FILE
When I open Excel and click on FILE on the menu bar, it only shows 4 previously opened documents. I want it to show 8-10 but can't find any options to change it. Can it be done? I have the student and teacher edition 2003. <Tools> <Options> <General> tab, Change number of entries by the "RecentlyUsedFileList". -- HTH, RD ============================================== Please keep all correspondence within the Group, so all may benefit! ============================================== "Carolyn" <anonymous@discussions.microsoft.com> wrote i...

notification when new mail arrive if outlook is not active
Is there possibility to have notification when new mail arrive, even outlook is not open >-----Original Message----- >Is there possibility to have notification when new mail >arrive, even outlook is not open >. > To set up a notification, go to Tools --> Options --> Email Options and check the box 'Display a notification message when new email arrives'. This can only work if Outlook is open. I now that but I need notification if Outlook is not started!!! >-----Original Message----- > >>-----Original Message----- >>Is there possibility...

How do I program my document so it always writes with the same fon
Hello. I have programmed my document to write in Verdana 9. But a problem arises when I change a little in the text. Somestimes it starts writing in Times New Roman. How do I program my document so it always writes with the same font. (Word 2003) Rasmus Create a paragraph style using that font and apply it to your text. -- <>>< ><<> ><<> <>>< ><<> <>>< <>><<> Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org <>>< ><<> ...

Money 2006 updating for hours
Won't let me process a scheduled transaction, says that I have to wait for update to finish. I have done quck repair, rebooted the computer several times. It won't shut down normally either. I just migrated from 2005 a few days ago. Thanks for your help In microsoft.public.money, armand wrote: >Won't let me process a scheduled transaction, says that I have to wait for >update to finish. I have done quck repair, rebooted the computer several >times. It won't shut down normally either. I just migrated from 2005 a few >days ago. Check that the SSL2 pro...

Activity without date
In my current project plan I know a few activities that will be conducted, more specifically meetings that are important. Now, I don't know the date they will happen yet and I want to indicate that by adding the activity but not entering a date. Is that allowed in MS Project? Since Project is designed to calculate dates, not only can you enter a task without a date, you should be entering ALL tasks without dates and then Project tells you when you should schedule them. -- Steve House MS Project Trainer & Consultant "Hertsh" <Hertsh@discussions.microsoft....

Changing margins on different pages in document templates.
I was wondering how you change the margins for different pages in a template. Specifically, my firm is using a letterhead for the first page but blank pages after that so the header and footer margins on the first page ONLY must be larger than normal, while the following pages are fine with default settings for the margins. How do you do this and save it as a template? See http://sbarnhill.mvps.org/WordFAQs/Letterhead.htm, especially the "More complex letterhead" section. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA http://wo...

excel's active cell
how to highlight the active cell with a color each time it moves angelaexceluser, have a look at Chip's addin here for one way to do it, http://www.cpearson.com/excel/RowLiner.htm -- Paul B Always backup your data before trying something new Please post any response to the newsgroups so others can benefit from it Feedback on answers is always appreciated! Using Excel 2002 & 2003 "angelaexceluser" <angelaexceluser@discussions.microsoft.com> wrote in message news:48BB20C8-3DF8-43AB-B913-9CDB2A288748@microsoft.com... > how to highlight the active cell with a color ...

Active Sync timeed out with DEV_10
I have problems with sync my mobile. normally the mobile syncs 100 Objects and then stops. Next time it syncs the next 100 objects and stops again. Does anybody know why just one hundred !? On the Device I got the following error (at the end of the log) =-=- [15/3/2006 9:26:8.0] -=-= =-=-=-= Server Response =-=-=- No Header Found, got error: 80070006 Thanks Marc ...

Accessing a document from classes that are included in a dialog
Hi, I have a dialog that includes a class "ListBoxPair" which includes "ListBox". In this class, I would like to access the doc to update variables What is the best way to do it? Many thanks Thank you very much. I am sorry for the stupid question, I am just new in it: Should I write a constructor that gets this argument? How should it look like? An additional question, when it works, how do I go up to get this doc (from the class I mentioned before)? Thank you very much for your help "Scott McPhillips [MVP]" wrote: > Liat wrote: > > Hi, > &g...

Display names in Global address book do not update
I made a change to one of my users so that their display name shows as last name, first name. This change has not been applied to the global address book, but you can see the change has been made in active directory users and computers. Any idea how I update this change for the global address book? Thanks, Mike YOu need to wait for the global catalogs to refresh.....depends on your AD topology. "Mike Fefferman" <mike@nowhere.com> wrote in message news:%23v%23sxI5PFHA.3156@TK2MSFTNGP15.phx.gbl... >I made a change to one of my users so that their display name show...

Entourage 2008 (12.2.4 update) meeting invites
Version: 2008 Operating System: Mac OS X 10.6 (Snow Leopard) Processor: Intel Email Client: Exchange I can't seem to send meeting invites from Entourage. I click on &quot;Invites&quot; and then enter an email address the &quot;send now&quot; button gets greyed out. Also, when an invite is received from Outlook the &quot;accept, decline and tentative&quot; buttons are greyed out as well. Right click option is the same too. We are using Exchange 2007 and any help would be appreciated... On 3/15/10 3:55 PM, Maunir@officeformac.com wrote: > I can't...

Can one have an extra margin gutter, for binding a document print.
I need to print Excel documents (landscape A4) on both sides of the paper, and bind them along the long edge. Thus I need an extra margin gutter along the top of odd pages, and along the bottom of even pages. (It's wasteful to put the extra margin on both top and bottom of every page...) Using Excel 2002 SP1. Hi Dave, AFAIK, Excel provides no options for true duplex printing. Headers/footers, margins, etc. are only geared for single-sided printing. You might want to consider using Word for that purpose. You have more page layout options that may give you what you want. Use Word...

Money won't update w/ bank's new sign in screens
I have accounts at two banks and was trying to set them up in Money 2006 to download automatically because they are both setup in the system. Accounts at one bank works just fine as expected. This bank has a normal signin process where I just log on with my username and passwords and that's it. The other bank, on their own website, has a 2 page login procedure with the picture verification thing so I know I'm on the right site. Money can't log in to this bank to get my account information. Does Money not support this type of new login procedures or something? Do I need ...

DST in Update Rollup 2
As per http://support.microsoft.com/kb/927751, DST patch (925874) is included in Rollup 2, has fix for 'New Zealand Standard Time'. We installed update rollup 2, User are in New Zealand time Zone. Activities created after rollup 2, and falls under delta period (Oct 1 to Oct 7) is not reflecting DSTchanges. Does anyone encountered similar problem and found remedy? I think you might need to use the patch referenced by KB937667, but I haven't been able to get it to work yet. Cheers Steve "Shankar VT" wrote: > As per http://support.microsoft.com/kb/927751, DST p...

Service activity scheduling
Hello, I have different sites providing the same service, I want that from service calendar, my users could schedule a service: 1) from the nearest site 2) if no resources available on this site, use any other site with available resources. Is CRM able to do this ? How to enter rules on the service to have this kind of selection ? Thanks for help. CS ------=_NextPart_0001_4D90D1A4 Content-Type: text/plain Content-Transfer-Encoding: 7bit Hi CS, Thank you for the post. This is Mike responding. I cannot find a way for CRM to perform this functionality. However, I can see where thi...

Update complete excel file online
Dear all, Hope you can help me with this problem. An excel file is updated on a daily basis and can only be found on the internet. The basic format of this file is always the same, the only changing aspect is the data. How, or if even possible, could I implement something (e.g. a button?) which automatically implements the updated sheet from the Internet. I am really looking forward to hearing from you. Thanks a lot and best regards, ...

MOC 8529A - CRM - Activate Ready Server
I've installed the ReadyServer in a Virtual PC 2004. Now I have to activate it. I get Product Keys from Microsoft Learning Partners, but they didn't work. Several letters like M, P, J etc. are not accepted. What should I do to activate the Virtual Machine? Do anyone know how to install the Virtual Machines for the students? Did I have to activate them three times a trainer and also for the students? How did the Installation function for the MOC 8529A. Are the Labs installed on the Virtual Machines? pls. help soon. Mindbl2000 EggHeadCafe - .NET Developer Portal of Choice http://w...

PWA 2007 Activity Task usage, not duration
Anyone know how I can have an activity task collect usage without duration? TIA! -JS DevourU -- Not possible. In an Activity plan, each task must have a Duration value. Hope this helps. -- Dale A. Howard [MVP] VP of Educational Services msProjectExperts http://www.msprojectexperts.com http://www.projectserverexperts.com "We write the books on Project Server" "DevourU" <DevourU@discussions.microsoft.com> wrote in message news:F0F6335E-EBF8-4CB6-8C0E-5AA3157FCDCD@microsoft.com... > Anyone know how I can have an activity task collect usa...

Index
Version: 2008 Operating System: Mac OS X 10.5 (Leopard) I know how to remove an index entry, and I can easily remove the index from the last page of my document. But I cannot remove each tagged index entry from the document without doing it individually. In a 77 page doc - this will take too long. Any ideas? Use Find/Replace. Search for ^d XE and replace with "nothing". Note: Case does matter. You will need to fiddle around to get this working: spacing is critical between ^d and the field name XE. I you do not have any other fields in use in the document (and you&...