#1
|
|||
|
|||
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
__________________
Jamal NUMAN, Jamal432@gmail.com, P.O.BoX: 731, Ramallah, West Bank. |
#2
|
||||
|
||||
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 [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Quote:
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
__________________
Jamal NUMAN, Jamal432@gmail.com, P.O.BoX: 731, Ramallah, West Bank. Last edited by Jamal NUMAN; 01-19-2012 at 11:15 AM. |
#4
|
||||
|
||||
Quote:
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:
Code:
Private Sub Document_Open() ActiveDocument.Fields.Update End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
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 |
#6
|
|||
|
|||
Quote:
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
__________________
Jamal NUMAN, Jamal432@gmail.com, P.O.BoX: 731, Ramallah, West Bank. |
#7
|
||||
|
||||
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 [Fmr MS MVP - Word] |
#8
|
|||
|
|||
Quote:
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
__________________
Jamal NUMAN, Jamal432@gmail.com, P.O.BoX: 731, Ramallah, West Bank. |
#9
|
|||
|
|||
Quote:
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
__________________
Jamal NUMAN, Jamal432@gmail.com, P.O.BoX: 731, Ramallah, West Bank. |
#10
|
||||
|
||||
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 Code:
Public WithEvents wdApp As Word.Application Public WithEvents wdDoc As Word.Document Code:
Dim wdAppClass As New ThisApplication Public Sub AutoExec() Set wdAppClass.wdApp = Word.Application End Sub 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
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#11
|
|||
|
|||
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
__________________
Jamal NUMAN, Jamal432@gmail.com, P.O.BoX: 731, Ramallah, West Bank. Last edited by macropod; 01-24-2012 at 01:19 AM. Reason: Deleted unnecessary quote of entire previous post |
#12
|
||||
|
||||
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:
As I am travelling, I am not in a position to review this matter more fully right now.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#13
|
|||
|
|||
Quote:
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
__________________
Jamal NUMAN, Jamal432@gmail.com, P.O.BoX: 731, Ramallah, West Bank. |
#14
|
|||
|
|||
Quote:
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
__________________
Jamal NUMAN, Jamal432@gmail.com, P.O.BoX: 731, Ramallah, West Bank. |
#15
|
|||
|
|||
Quote:
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
__________________
Jamal NUMAN, Jamal432@gmail.com, P.O.BoX: 731, Ramallah, West Bank. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Macro to update fields | rhatx | Word VBA | 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 | 2 | 05-21-2009 08:49 AM |