Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Word

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 04-25-2011, 02:46 PM
Jamal NUMAN Jamal NUMAN is offline Windows XP Office 2007
Expert
 
Join Date: Nov 2010
Posts: 486
Jamal NUMAN is on a distinguished road
Question Does Word have an option to update fields AUTOMATICALLY at open???

Does Word have an option to update fields AUTOMATICALLY at open???



Word does have an option to update fields before printing and links at open (attached), but how to update the fields AUTOMATICALLY at open without pressing F9?


thank you

regards

Jamal
Attached Images
File Type: jpg Clip_90.jpg (81.3 KB, 29 views)
File Type: jpg Clip_91.jpg (88.7 KB, 28 views)
Reply With Quote
  #2  
Old 04-25-2011, 04:11 PM
macropod's Avatar
macropod macropod is offline Windows 7 32bit Office 2000
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 15,631
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

Hi Jamal

No, though some fields do update on open and others update immediately their references change. A print preview updates most fields.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #3  
Old 01-18-2012, 01:56 PM
Jamal NUMAN Jamal NUMAN is offline Windows 7 64bit Office 2010 64bit
Expert
 
Join Date: Nov 2010
Posts: 486
Jamal NUMAN is on a distinguished road
Question

Quote:
Originally Posted by macropod View Post
Hi Jamal

No, though some fields do update on open and others update immediately their references change. A print preview updates most fields.
Hi Paul,

I’m still wondering why –up to now- there isn't an option that updates all the fields automatically! For example, the only field that can be updated automatically (when any change occurs) is the “Date” field! Why this option is exclusively set to the “Data” field?
All other fields are updated by two ways:
1. Either by using the command “Update field”! this not practical since it needs to be clicked manually
2. Or by checking the option “Update fields before printing”! this is not practical since it depends on the setting of the “Word” on the computer
What I’m looking for is to have an option that can update the fields automatically when any change occurs!
Is there such option?
For instance, when the “FileName” field is inserted, why it is not AUTOMATICALLY changed as the name of file is changed? Why do we need to use the command “Update field” MANUALLY to perform this?


the screenshots are attached
Thank you in advance,
Regards
Jamal
Attached Images
File Type: jpg Clip_268.jpg (93.3 KB, 25 views)
File Type: jpg Clip_269.jpg (109.7 KB, 23 views)
File Type: jpg Clip_270.jpg (71.3 KB, 23 views)

Last edited by Jamal NUMAN; 01-19-2012 at 11:15 AM.
Reply With Quote
  #4  
Old 01-19-2012, 03:22 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 15,631
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

Quote:
Originally Posted by Jamal NUMAN View Post

I’m still wondering why –up to now- there is an option that updates all the fields automatically!
That's not correct. Word has never had such an option, but has had an option to update links automatically. Whilst links use fields, not all fields are links. There are numerous fields a user wouldn't want to update automatically, including ASK & FILLIN fields.

Some years ago, MS did change the update of some fields that previously updated automatically in the body of the document, but not all. Fields that do still update automatically include most fields ordinarily used in page headers/footers (and this includes certain fields that don't update automatically when in the body of the document).

And yes, there is an option that updates all fields automatically if any of them change - its any formfield that has the 'calculate on exit' option checked. Of course, you wouldn't want to use one of these in most documents as the forms protection that these require severely restricts editing.

Quote:
Does Word have an option to update fields AUTOMATICALLY at open???
No, for the reasons explained. What is possible, though not necessarily advisable, is to add macros to, say, Word's Normal template to trigger the field updating any time a document is opened or saved. A macro that might be used in the Normal template's 'This Document' module is:
Code:
Private Sub Document_Open()
  ActiveDocument.Fields.Update
End Sub
but even this will only update fields in the body of the document.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #5  
Old 01-19-2012, 04:27 AM
Catalin.B Catalin.B is offline Windows Vista Office 2010 32bit
Expert
 
Join Date: May 2011
Location: Iaşi, România
Posts: 388
Catalin.B is on a distinguished road
Default

Another thing you can do, is to place this code in Normal Template's This Document module, then place a button on the quick acces toolbar with this macro assigned, to update fields whenever you decide to...
Code:
Sub UpdateAllFields()

Dim oStory As Range
For Each oStory In ActiveDocument.StoryRanges
    oStory.Fields.Update
    If oStory.StoryType <> wdMainTextStory Then
        While Not (oStory.NextStoryRange Is Nothing)
            Set oStory = oStory.NextStoryRange
            oStory.Fields.Update
        Wend
    End If
Next oStory
Set oStory = Nothing
End Sub
Reply With Quote
  #6  
Old 01-19-2012, 11:46 AM
Jamal NUMAN Jamal NUMAN is offline Windows 7 64bit Office 2010 64bit
Expert
 
Join Date: Nov 2010
Posts: 486
Jamal NUMAN is on a distinguished road
Question

Quote:
Originally Posted by macropod View Post
That's not correct. Word has never had such an option, but has had an option to update links automatically. Whilst links use fields, not all fields are links. There are numerous fields a user wouldn't want to update automatically, including ASK & FILLIN fields.

Some years ago, MS did change the update of some fields that previously updated automatically in the body of the document, but not all. Fields that do still update automatically include most fields ordinarily used in page headers/footers (and this includes certain fields that don't update automatically when in the body of the document).

And yes, there is an option that updates all fields automatically if any of them change - its any formfield that has the 'calculate on exit' option checked. Of course, you wouldn't want to use one of these in most documents as the forms protection that these require severely restricts editing.

No, for the reasons explained. What is possible, though not necessarily advisable, is to add macros to, say, Word's Normal template to trigger the field updating any time a document is opened or saved. A macro that might be used in the Normal template's 'This Document' module is:
Code:
Private Sub Document_Open()
  ActiveDocument.Fields.Update
End Sub
but even this will only update fields in the body of the document.
Thank you Paul and Catalin.B for the informative answer. This is very helpful
1. I’m sorry Paul for the mistake in my previous post! I meant “I’m still wondering why –up to now- there is NOT an option that updates all the fields automatically”
2. I tried the code that you have provided that updates the fields in case of saving and opening the file. But unfortunately it didn’t work! Please, have a look on the screenshot 1.
What might be my mistake?
3. Also, I tried the code provided by Catalin.B and it worked very well. But what I’m looking for is to get all the fields updated AUTOMATICALLY as the file: open, saved, printed, …
Regards
Jamal
Attached Images
File Type: jpg Clip_282.jpg (91.9 KB, 22 views)
File Type: jpg Clip_283.jpg (111.0 KB, 22 views)
Reply With Quote
  #7  
Old 01-20-2012, 02:30 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 15,631
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

Hi Jamal,

The code I supplied only works during the process of opening a document, so how do you know it wasn't working?
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #8  
Old 01-20-2012, 04:19 AM
Jamal NUMAN Jamal NUMAN is offline Windows 7 64bit Office 2010 64bit
Expert
 
Join Date: Nov 2010
Posts: 486
Jamal NUMAN is on a distinguished road
Question

Quote:
Originally Posted by macropod View Post
Hi Jamal,

The code I supplied only works during the process of opening a document, so how do you know it wasn't working?
Thank you Paul for the prompt answers.
1. I thought that the macro is updating the fields when the document is saved as well. Sure it updates the fields as the file is opened
2. I have attached this macro to the “this document” of a certain file (project) as shown in screenshot 1, it worked properly but it didn’t update the fields existing on the header or footer
I’m not sure if the micro can be developed to:
- - Update the fields when the document is saved, opened, printed, ….
- - Update the fields existing on the header and footer or anywhere on the document
I do appreciate your distinct efforts.
All the best
Jamal
Attached Images
File Type: jpg Clip_300.jpg (108.4 KB, 21 views)
File Type: jpg Clip_299.jpg (89.1 KB, 21 views)
Reply With Quote
  #9  
Old 01-20-2012, 04:42 AM
Jamal NUMAN Jamal NUMAN is offline Windows 7 64bit Office 2010 64bit
Expert
 
Join Date: Nov 2010
Posts: 486
Jamal NUMAN is on a distinguished road
Question

Quote:
Originally Posted by Catalin.B View Post
Another thing you can do, is to place this code in Normal Template's This Document module, then place a button on the quick acces toolbar with this macro assigned, to update fields whenever you decide to...
Code:
Sub UpdateAllFields()

Dim oStory As Range
For Each oStory In ActiveDocument.StoryRanges
    oStory.Fields.Update
    If oStory.StoryType <> wdMainTextStory Then
        While Not (oStory.NextStoryRange Is Nothing)
            Set oStory = oStory.NextStoryRange
            oStory.Fields.Update
        Wend
    End If
Next oStory
Set oStory = Nothing
End Sub
Hi Colin,

As I have already posted in the previous participation, can the macro (that you have provided) be developed to be embedded to a specific document (screenshot 1) such that:
· All the fields are updated when: save, save as, open or print are clicked
· All fields existing in the header and footer are updated are well
In this case, I think that I’m forced to save the document as *.docm, is that true?
Is there a way to have this property with the regular file extension (*.docx)?
Many thanks
Jamal
Attached Images
File Type: jpg Clip_300.jpg (108.4 KB, 21 views)
Reply With Quote
  #10  
Old 01-21-2012, 11:33 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 15,631
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

Hi Jamal,

Yes, that is possible, but requires a fair bit of code to implement. For the open/close side of things, add the following code to your 'Normal' template's 'ThisDocument' module:
Code:
Sub RefreshFields(Doc As Document)
Dim TOC As TableOfContents  ' Table of Contents Object
Dim TOA As TableOfAuthorities ' Table of Authorities Object
Dim TOF As TableOfFigures ' Table of Figures Object
Dim pRange As Range ' Word Range Object
With Doc
  ' Loop through Story Ranges and update.
  ' Note that this may trigger interactive fields (eg ASK and FILLIN).
  For Each pRange In .StoryRanges
    Do
      pRange.Fields.Update
      Set pRange = pRange.NextStoryRange
    Loop Until pRange Is Nothing
  Next
' The following routines are necessary because the foregoing updates only page numbers
' in TOCs, TOAs and TOFs - field updating doesn't update TOC, TOA or TOF contents.
  ' Loop through Tables Of Contents and update
  For Each TOC In .TablesOfContents
    TOC.Update
  Next
  ' Loop through Tables Of Authorities and update
  For Each TOA In .TablesOfAuthorities
    TOA.Update
  Next
  ' Loop through Tables Of Figures and update
  For Each TOF In .TablesOfFigures
    TOF.Update
  Next
End With
Call AcceptTrackedFields(Doc)
End Sub
 
Sub AcceptTrackedFields(Doc As Document)
'This sub accepts any tracked changes affecting fields
Dim oRng As Range, oFld As Field
With Doc
  ' Loop through all range objects and accept tracked changes on fields
  For Each oRng In .StoryRanges
    Do
      For Each oFld In oRng.Fields
        oFld.Select
        Selection.Range.Revisions.AcceptAll
      Next
      Set oRng = oRng.NextStoryRange
    Loop Until oRng Is Nothing
  Next
End With
End Sub
 
Private Sub Document_Close()
Dim bSaved As Boolean
bSaved = ActiveDocument.Saved
Call RefreshFields(ActiveDocument)
If bSaved = True And ActiveDocument.Saved = False Then ActiveDocument.Save
End Sub
 
Private Sub Document_Open()
Call RefreshFields(ActiveDocument)
End Sub
To intercept printing & saving requires creating events to intercept. Using Events requires that you instantiate the app object class. To do this, create a new class module in the Normal template to register your events. At the top of the module put:
Code:
Public WithEvents wdApp As Word.Application
Public WithEvents wdDoc As Word.Document
Then, in a normal code module in the template, put:
Code:
Dim wdAppClass As New ThisApplication
Public Sub AutoExec()
Set wdAppClass.wdApp = Word.Application
End Sub
This will allow you to get events from your Word document. Now you can add the following code to your Normal template's 'This Document' module:
Code:
Private Sub wdApp_DocumentBeforePrint(ByVal Doc As Document, Cancel As Boolean)
Call RefreshFields(ActiveDocument)
End Sub
 
Private Sub wdApp_DocumentBeforeSave(ByVal Doc As Document, Cancel As Boolean)
Call RefreshFields(ActiveDocument)
End Sub
Note that I haven't tested this code (though it should work) and don't know what the outcome might be with all the different kinds of documents one might work with. In some cases (eg documents with ASK & FILLIN fields), the results may well be undesirable.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #11  
Old 01-22-2012, 12:13 PM
Jamal NUMAN Jamal NUMAN is offline Windows 7 64bit Office 2010 64bit
Expert
 
Join Date: Nov 2010
Posts: 486
Jamal NUMAN is on a distinguished road
Question

Thank you Paul for the enormous efforts. This is quite useful.



1. The issue now is how to embed this code to the “this document” of the “Project” but not to the “this document” of the “Normal” (please see the attached screenshot).




2. When I embed this code to the “this document” of the “project”, I assume that this code is going to update all the fields (even the ones in the header and footer) when the document is: saved, saved as, opened or printed




3. The asset of saving this code in the “this document” of the “project” is that the code is going to work in any computer without the need to build the code on the “this document” of the “Normal




4. In case the code is built on the “this document” of the “project”, is the file saved exclusively in *.docm format?




5. I’m attaching the docm file in which I’ve built the code you have already supplied. It is working very well when the document is saved but unfortunately it doesn’t work when it is saved, saved as or printed





Could you please elaborate more in how to build the code that you have already provided such that all the fields of the “this document” of the “Project” are updated in saving, saving as, open, print,…?




All the best




Jamal
Attached Images
File Type: jpg Clip_4.jpg (129.5 KB, 24 views)
File Type: jpg Clip_5.jpg (119.4 KB, 23 views)
File Type: jpg Clip_6.jpg (114.8 KB, 22 views)
File Type: jpg Clip_7.jpg (118.1 KB, 21 views)
Attached Files
File Type: zip Doc1_04.zip (20.3 KB, 4 views)

Last edited by macropod; 01-24-2012 at 01:19 AM. Reason: Deleted unnecessary quote of entire previous post
Reply With Quote
  #12  
Old 01-24-2012, 01:29 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 15,631
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

Hi Jamal,

1. The procedure for adding the code to a particular document, instead of to the Normal template, is exactly the same. However, every reference to 'ActiveDocument' should be changed to 'ThisDocument'.
2 & 3. That is correct.
4. You can store the code in doc or docm files, not in docx files
5. Your comment is contradictory:
Quote:
It is working very well when the document is saved but unfortunately it doesn’t work when it is saved, saved as or printed
Does it work when saving, or does it not? AFAIK, the 'wdApp_DocumentBeforeSave' module, if correctly implemented in a Class Module, should work for both 'Save' and 'Save As' procedures.

As I am travelling, I am not in a position to review this matter more fully right now.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #13  
Old 01-24-2012, 12:59 PM
Jamal NUMAN Jamal NUMAN is offline Windows 7 64bit Office 2010 64bit
Expert
 
Join Date: Nov 2010
Posts: 486
Jamal NUMAN is on a distinguished road
Question

Quote:
Originally Posted by macropod View Post
Hi Jamal,

1. The procedure for adding the code to a particular document, instead of to the Normal template, is exactly the same. However, every reference to 'ActiveDocument' should be changed to 'ThisDocument'.
2 & 3. That is correct.
4. You can store the code in doc or docm files, not in docx files
5. Your comment is contradictory:
Does it work when saving, or does it not? AFAIK, the 'wdApp_DocumentBeforeSave' module, if correctly implemented in a Class Module, should work for both 'Save' and 'Save As' procedures.

As I am travelling, I am not in a position to review this matter more fully right now.
Thank you for the massive effort. I do appreciate it.
Apologies for the mistakes on my previous post and bothering you with more problems.
In short, what I wanted is to stick a code inside a particular document such that all the fields are updated automatically as I: save, save as, open and print.
It would be highly appreciated if your time allows to stick the codes that you have supplied in a particular document (and kindly send it) in the right place (Microsoft word objects, modules, class modules, references) such that I can use it as a master document. I tried to do that but sounds not to work (attached).
I to remind you with this thread when you come back!
Wish you a nice and safe trip. Take care.
Best regards
Jamal
Attached Files
File Type: zip Doc1_06.zip (20.4 KB, 2 views)
Reply With Quote
  #14  
Old 01-26-2012, 03:14 PM
Jamal NUMAN Jamal NUMAN is offline Windows 7 64bit Office 2010 64bit
Expert
 
Join Date: Nov 2010
Posts: 486
Jamal NUMAN is on a distinguished road
Lightbulb

Quote:
Originally Posted by macropod View Post
Hi Jamal,

1. The procedure for adding the code to a particular document, instead of to the Normal template, is exactly the same. However, every reference to 'ActiveDocument' should be changed to 'ThisDocument'.
2 & 3. That is correct.
4. You can store the code in doc or docm files, not in docx files
5. Your comment is contradictory:
Does it work when saving, or does it not? AFAIK, the 'wdApp_DocumentBeforeSave' module, if correctly implemented in a Class Module, should work for both 'Save' and 'Save As' procedures.

As I am travelling, I am not in a position to review this matter more fully right now.
I'm not sure if you still remember the issue of showing the name of the file and path on the title bar of the MS Access.

i got a code from the forum (with autoexec) which is implemented as the file open (attached), in this case, it writes the name and the path of the file on the title bar

I'm looking for such code that updates all the fields as we: save, save as, open and print.

best

Jamal
Attached Images
File Type: jpg Clip_41.jpg (100.4 KB, 22 views)
Attached Files
File Type: zip m.zip (15.6 KB, 4 views)
Reply With Quote
  #15  
Old 01-26-2012, 04:03 PM
Jamal NUMAN Jamal NUMAN is offline Windows 7 64bit Office 2010 64bit
Expert
 
Join Date: Nov 2010
Posts: 486
Jamal NUMAN is on a distinguished road
Question

Quote:
Originally Posted by Catalin.B View Post
Another thing you can do, is to place this code in Normal Template's This Document module, then place a button on the quick acces toolbar with this macro assigned, to update fields whenever you decide to...
Code:
Sub UpdateAllFields()

Dim oStory As Range
For Each oStory In ActiveDocument.StoryRanges
    oStory.Fields.Update
    If oStory.StoryType <> wdMainTextStory Then
        While Not (oStory.NextStoryRange Is Nothing)
            Set oStory = oStory.NextStoryRange
            oStory.Fields.Update
        Wend
    End If
Next oStory
Set oStory = Nothing
End Sub
Hi Catalin,

I'm not sure if this code can be developed to be embedded in the document (and work through a macro) to update the fields automatically as we: save, save as, open, or print.

thank you

regards

Jamal
Reply With Quote
Reply
Please reply to this thread with any new information or opinions.

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to update fields rhatx Word 0 03-02-2011 12:14 PM
VBA to update certain (but not all) fields sparkyrose Word VBA 0 05-20-2010 12:50 PM
Can no longer update fields! slindsay Word 0 09-03-2009 05:10 PM
Automatically update text changes in word – Word 2007 webarnes Word 1 05-29-2009 02:48 PM
Automatically update text changes in Word - how do I do it? jonrm Word 3 05-23-2009 01:47 AM


All times are GMT -7. The time now is 12:28 PM.


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