Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-23-2016, 02:51 PM
pmcpowell pmcpowell is offline Finding And Updating "ref" Fields Using Code Windows 8 Finding And Updating "ref" Fields Using Code Office 2013
Novice
Finding And Updating "ref" Fields Using Code
 
Join Date: Feb 2016
Posts: 6
pmcpowell is on a distinguished road
Default Finding And Updating "ref" Fields Using Code

Hi - This is my first post in the Forum - I posted to Utter Access which has a Word forum but they thought that you would be better equipped to answer my question:

I have created an 18 page document which contains many "Ref" Fields which are updated from Bookmarks which are accessed through a single Data Page. I have created an update MacroButton which I recorded the actions of Goto the "DocStart" Bookmark - CTRL+Shift+END to select the entire document from that point onward and then Fn+F9 to update all of the fields contained within that range.

The button seems to work in that it runs the macro but does not always update all of the Ref Fields. When I don't use the MacroButton and just perform the actions, it seems to update more of the fields but not always all of them.
I must add that some of the fields are inside Tables and Text Boxes, but not in Headers or Footers. However there is no clear condition which applies to all of the non-updating fields.



I was wanting to create code to loop through all of the "Ref" Fields and Update individually but I cannot seem to extract the contents of the fields in ordr to identify them using the "ActiveDocument.Fields.Item() but haven't been successful as if I try to populate a variable using that code, I get a Type Mismatch error.

As I want to share this document with other Coworkers I would love to have complete automation.

Any help would be greatly appreciated.

Peter
Reply With Quote
  #2  
Old 02-23-2016, 03:28 PM
macropod's Avatar
macropod macropod is offline Finding And Updating "ref" Fields Using Code Windows 7 64bit Finding And Updating "ref" Fields Using Code Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,340
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Ordinarily, you should be able to use code like:
Code:
Sub UpdateFields()
Application.ScreenUpdating = False
With ActiveDocument
  .Fields.Update
  .PrintPreview
  .ClosePrintPreview
End With
Application.ScreenUpdating = True
End Sub
If that doesn't work, try:
Code:
Sub UpdateFields()
Application.ScreenUpdating = False
Dim pRange as Range
For each pRange in ActiveDocument.StoryRanges
  Do
    pRange.Fields.Update
    set pRange = pRange.NextStoryRange
  Loop until pRange is Nothing
Next
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 02-23-2016, 06:28 PM
pmcpowell pmcpowell is offline Finding And Updating "ref" Fields Using Code Windows 8 Finding And Updating "ref" Fields Using Code Office 2013
Novice
Finding And Updating "ref" Fields Using Code
 
Join Date: Feb 2016
Posts: 6
pmcpowell is on a distinguished road
Default

Thanks Macropod - I did a count on the fields and was surprised to see 315. As I only created about 50 I was wondering if I could just identify and only update the "Ref" fields.
Thanks - Peter
Reply With Quote
  #4  
Old 02-23-2016, 06:36 PM
macropod's Avatar
macropod macropod is offline Finding And Updating "ref" Fields Using Code Windows 7 64bit Finding And Updating "ref" Fields Using Code Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,340
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Updating individual fields is a much slower process than updating all in one go, as each field's type has to be tested. Is there a reason for wanting to take such an approach?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 02-23-2016, 06:56 PM
pmcpowell pmcpowell is offline Finding And Updating "ref" Fields Using Code Windows 8 Finding And Updating "ref" Fields Using Code Office 2013
Novice
Finding And Updating "ref" Fields Using Code
 
Join Date: Feb 2016
Posts: 6
pmcpowell is on a distinguished road
Default

No specific reason other than wondering what other fields I am updating which I may not want updated - However I just tried out the second sub you gave me and it seems to work just fine - very grateful indeed. Nice neat few lines of code :-)
One thing which seems to bother me though is that although I check the "Preserve Formatting" box in Edit Fields", some fields seem to defy preservation and need to be re-formatted manually after updates.
Reply With Quote
  #6  
Old 02-23-2016, 07:24 PM
macropod's Avatar
macropod macropod is offline Finding And Updating "ref" Fields Using Code Windows 7 64bit Finding And Updating "ref" Fields Using Code Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,340
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by pmcpowell View Post
No specific reason other than wondering what other fields I am updating which I may not want updated
The only time that's likely to be an issue is if you have ASK or FILLIN fields, which will prompt for inputs or, perhaps, DATABASE, INCLUDEPICTURE, INCLUDETEXT, RD & LINK fields, as those reference external files - and updating them takes longer. But not updating them also risks using outdated data... If you're wanting REF fields to update, you'd almost certainly want PAGEREF, NOTEREF & SEQ fields to update, too.
Quote:
Originally Posted by pmcpowell View Post
One thing which seems to bother me though is that although I check the "Preserve Formatting" box in Edit Fields", some fields seem to defy preservation and need to be re-formatted manually after updates.
In general, you're better off not using that option with REF fields, especially, as REF fields using them tend to get the formatting messed up if you increase the content of whatever they refer to.

You can use Find/Replace to clear the "Preserve Formatting" attribute from existing fields. To do that:
• press Alt-F9 to expose the document's field codes
• do a Find/Replace where:
Find = ^w\* MERGEFORMAT^w
Replace = nothing
• press Alt-F9 to hide the document's field codes
• press F9 to update the field display.

If you're wanting to force a field to display in a particular way (e.g. Bold, Italics, 18pt, Arial), you can use a \* CHARFORMAT switch. To do that:
• Select the field of interest and press Shit-F9 to expose it's field code
• add a \* CHARFORMAT switch to the end of the field code
• format at least the first character of the field code with the font attributes that you want the field to use
• press F9 to update the field display.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 02-23-2016, 07:46 PM
pmcpowell pmcpowell is offline Finding And Updating "ref" Fields Using Code Windows 8 Finding And Updating "ref" Fields Using Code Office 2013
Novice
Finding And Updating "ref" Fields Using Code
 
Join Date: Feb 2016
Posts: 6
pmcpowell is on a distinguished road
Default

Thanks for the info - getting late now, will give it a shot tomorrow. I am so grateful for your help :-)
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding And Updating "ref" Fields Using Code vb code for updating file automatically klpw Excel Programming 1 01-14-2016 08:05 PM
Finding And Updating "ref" Fields Using Code Updating fields in word on save Macer Word VBA 8 02-09-2015 03:31 PM
Finding And Updating "ref" Fields Using Code Word 2013 Fields not updating awaywithpixie Word 1 09-10-2013 10:35 AM
Finding And Updating "ref" Fields Using Code Automatically updating document as fields are completed. Calab Word 2 06-27-2013 08:55 AM
Finding And Updating "ref" Fields Using Code Phantom spaces when updating linked fields freefalladdict Word 3 01-08-2012 02:23 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:52 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft