#1
|
|||
|
|||
Word Field Update
How do we pragmatically find out that fields needs to be updated in the document before calling fields.Update()?? Thanks! |
#2
|
||||
|
||||
Interesting question. I have no idea.
The only way I think you could tell is by updating the field and then comparing the result with the previous value.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
|||
|
|||
Thanks! Could you tell me how can I programmatically compare the result?
|
#4
|
||||
|
||||
Try this macro:
Code:
Sub FieldsUpdated() Dim aFld As Field, sBefore As String, sAfter As String Dim sMsg As String, iChangeCount As Integer For Each aFld In ActiveDocument.Fields sBefore = aFld.Result aFld.Update sAfter = aFld.Result If sBefore <> sAfter Then aFld.Result.HighlightColorIndex = wdDarkYellow iChangeCount = iChangeCount + 1 End If Next aFld If iChangeCount > 0 Then MsgBox iChangeCount & " field(s) were changed. Look for the dark yellow highlights" Else MsgBox "No field changes" End If End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#5
|
|||
|
|||
Note, you probably want to run that on a copy of your document.
|
#6
|
||||
|
||||
Out of curiosity, why do you want to know if a field has been updated? It won't do any harm to update it whenever you want to ensure that the display is up to date (even if the field is already displaying the updated result).
__________________
Stefan Blom Microsoft Word MVP Microsoft 365 apps for business Windows 11 Professional |
#7
|
||||
|
||||
Cross-posted (and answered before posting here) at: https://social.msdn.microsoft.com/Fo...?forum=worddev
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184 Manohar: This is the third time you've been asked in this forum to provide cross-post links. Consider this a final warning - cross-post again without providing links and your account will be terminated. Thread closed.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
Tags |
fields |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Update & Unlink Specific Merge Field in Word Doc from Mail Merge - Excel VBA | RMerckling | Mail Merge | 16 | 05-17-2018 05:19 PM |
Force Word (2007) to only update date field when asked to | ShankedS | Word | 5 | 10-25-2016 06:45 AM |
Can field dynamically update? | namedujour | Word | 2 | 03-04-2016 10:21 PM |
VBA script to update field codes? | Calab | Word VBA | 1 | 04-07-2014 09:27 PM |
Auto update Filename field | Oliver Beirne | Word VBA | 4 | 10-19-2012 03:33 AM |