Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Word VBA

Closed Thread
 
LinkBack Thread Tools Display Modes
  #1  
Old 06-13-2018, 10:31 PM
MANOHAR MANOHAR is offline Windows 7 32bit Office 2007
Advanced Beginner
 
Join Date: Jan 2017
Posts: 33
MANOHAR is on a distinguished road
Default Word Field Update

How do we pragmatically find out that fields needs to be updated in the document before calling fields.Update()??



Thanks!
  #2  
Old 06-14-2018, 01:31 AM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 737
Guessed is on a distinguished road
Default

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  
Old 06-14-2018, 02:03 AM
MANOHAR MANOHAR is offline Windows 7 32bit Office 2007
Advanced Beginner
 
Join Date: Jan 2017
Posts: 33
MANOHAR is on a distinguished road
Default

Thanks! Could you tell me how can I programmatically compare the result?
  #4  
Old 06-14-2018, 03:24 AM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 737
Guessed is on a distinguished road
Default

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  
Old 06-14-2018, 05:40 AM
Charles Kenyon Charles Kenyon is offline Windows 10 Office 2013
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 5,094
Charles Kenyon is a glorious beacon of lightCharles Kenyon is a glorious beacon of lightCharles Kenyon is a glorious beacon of lightCharles Kenyon is a glorious beacon of lightCharles Kenyon is a glorious beacon of lightCharles Kenyon is a glorious beacon of light
Default

Note, you probably want to run that on a copy of your document.
  #6  
Old 06-17-2018, 04:06 PM
Stefan Blom's Avatar
Stefan Blom Stefan Blom is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2011
Posts: 2,873
Stefan Blom is a jewel in the roughStefan Blom is a jewel in the roughStefan Blom is a jewel in the rough
Default

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
  #7  
Old 06-17-2018, 07:18 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 17,649
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

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
[MS MVP - Word]
Closed Thread

Tags
fields

Thread Tools
Display Modes


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


All times are GMT -7. The time now is 01:32 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
MSOfficeForums.com is not affiliated with Microsoft