Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word 2007 - Update Headers & More with same data

Status
Not open for further replies.

addy

Technical User
May 18, 2001
743
GB
OK, I have searched on Google for too long and can't find an answer (maybe my search requests are badly worded).

I have a Document which is a Test Plan for a Web Application. One of the things we enter on the Test Plan is the current Version Number of the application. This is currently displayed on the Front Cover and also in the Headers.

Is there anyway of being able to enter the Version Number somewhere in the Document just once, and for it to then update in the Headers, or anywhere else it is needed? Currently the tester has to update all occurrences of it.

Thanks.
 
If you create a Custom Document Property (Office Button > Prepare > Properties, click the Document Properties dropdown arrow and select Advanced Properties > Custom tab) then you can put a Field (or several) anywhere in the document - press Ctrl+F9 to get a pair of field braces and between them type "DocProperty Version" (or whatever you've called your custom property). The field(s) will reflect the value of the property, but will need updating. You can explicitly update fields by selecting them (individually or en masse) and pressing F9; Fields in headers and footers will be automatically updated by default when you print them (or just go into Print Preview).

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
Tony, thanks for the response but I'm afraid I can't get it to work :(

I did as you said, went to the Advanced Properties > Custom and entered VersionNumber as the Name: and then entered 4.5.2 (as a test) into the Value: box, leaving Type: as Text and clicked OK.

I then clicked into the Document where I wanted it to appear, did Ctrl+F9 to get the braces and entered VersionNumber in there.

However, when I toggle the Field Codes to display the Version Number, it says:

Error! Bookmark not defined.

Any ideas?

Thanks again.
 
OK - I've worked out how to make it display properly:

{ DOCPROPERTY VersionNumber \* MERGEFORMAT }

So, next question!!

Is there an easy way (or even a hard way) of prompting the User to enter this value when opening the Document and updating the custom property with this information?

I'm thinking a macro which fires on the document opening, with a prompt for a value but I am not sure how to reference the custom properties in VBA with Word (all my VBA experience is with Access).

Thanks again!
 
Never mind - figured it out :)
 
Hi, addy.

It may not be bad idea to post what you figured out. It may become useful for someone else.

Canadian eh! Check out the new social forum Tek-Tips in Canada.
With the state of the world today, monkeys should get grossly insulted when humans claim to be their decendents
 
Hi Addy,

If you only need the Version # to appear on the "Front Cover and also in the Headers", you could apply a unique Style Name to the Front Cover's Version # paragraph, then use a STYLEREF field in the Header to refer back to that Style.


Cheers
[MS MVP - Word]
 
Thanks for that macropod. It also appears in a couple of other places as well (don't ask me why but 'apparently' it needs to).

Anyway, I have it working now so that when someone opens the Document, it prompts them for the Version number and then updates all relevant fields.

Nice suggestion though, not one I knew how to do and might use it for a couple of other things.

Trying to get to grips with Word VBA. All my previous development is in Access, not too different but I don't know the Object references etc. in Word, although I am finding a lot of use for ActiveDocument. :)
 
Hi Addy,

There's no vba in any of the suggestions you've been offered - it's all based around the use of field coding, plus the use of either document properties or Styles.


Cheers
[MS MVP - Word]
 
I realise that, but I've been using VBA to prompt the User to enter the information when they open the document and then using their entry to set the value of the custom document property I created. It then also updates all relevant fields so the User doesn't have to update the fields themselves.

I appreciate the solutions above don't use VBA, but once I'd got my head around the custom properties and referencing Fields to them, I have added some VBA in a macro to smooth the process a bit.
 
Hi addy,

I do not think VBA should be necessary. An {Ask ..} field and subsequent {Ref ..} fields would do the job as well.
As you can enter a default value in the ASK field with the \d switch it could be even more comfortable for the user.

Regards,

M.
 
Hi Markus,

Unfortunately, ASK fields (and FILLIN fields) don't fire when the document is opened - only when you deliberately update the fields (eg Ctrl-A, F9) or send the document to the printer with the 'Update Fields' option checked.


Cheers
[MS MVP - Word]
 
Hi macropod,

thank you. I know I should have thought of that before posting. Sorry.

As the document is given to persons testing an application I assume it may contain macros. To keep things simple I therefore still would use an ASK field at the beginning and several REF fields throughout the document.

In a normal module (which I would create by recording a macro which does nothing - yes, I'm that lazy) I would put:
Code:
Sub AutoOpen()
'aktualisiert das Frage-Feld schon beim Öffnen
  Dim ff As Field
  For Each ff In ActiveDocument.Fields
    If ff.Type = wdFieldAsk Then ff.Update
  Next ff
End Sub 'AutoOpen(), MH 01.02.10
AutoOpen still works (even though there is Document_Open) in Word97 and Word2003, which is where I tested this.

Regards,

Markus
 
In a normal module (which I would create by recording a macro which does nothing - yes, I'm that lazy)

That is NOT lazy. That takes more work than, in the VBE, clicking Insert > Module.

Voila!

Versus:

Tools > Macro > Record new macro
Click Ok for default Macro1 name
Click Stop button of macro recorder

It is NOT lazy to do five clicks (at minimum) against TWO clicks.

Gerry
 
Hi Gerry,

I really do not want to even sound "rechthaberisch",* but I still think recording an empty macro is faster than writing one in VBE.
When you record an empty macro you get 1) a module (in some cases it might already exist) and 2) a procedure on it like:
Code:
Sub Makro1()
'
' Makro1 Makro
' Makro aufgezeichnet am 03.02.2010 von Kontakt- und Informationsstelle für Selbsthilfe
'
End Sub
Whenever I insert a module in VBE, there is no procedure on it.

Am I missing something?

Regards,

Markus
______________
* which is translated by dict.leo.org (a site I can only recommend) as self-opininated or self-righteous
 
I still think recording an empty macro is faster than writing one in VBE."

That is most certainly true...if the purpose and intention is to have an empty procedure. Although why you want an empty procedure I do not know.

However, the origianl comment was regarding creating a module

"In a normal module (which I would create"

I stand by my comment. Creating a module is faster by...creating a module. You could even name it the default name Word uses for recorded macros. That way, if you DO record a macro, it will be written there.

But...whatever.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top