Set a global date in a word document

G

giovanni

I created a template of a document which contains the same date in different
places with different formats (YYYY/MM, d MM YYYY, etc.).

When I use the template, I would like to set the date in a unique place and
have Word update all dates for me. I am using Word 2007, how do you suggest
to proceed? Thanks
 
H

Herb Tyson [MVP]

Bookmark the date in that unique place (select and choose Insert -
Bookmark), then insert references (press Ctrl+F9, type ref bookmarkname,
then press F9) to it where you want it to appear. You would need to update
(select and press F9) the reference fields when the original source date
changes.
 
G

Graham Mayor

To add to Herb's reply, as long as the date you bookmark has a legitimate
date format, you can use formatting switches on the REF field to provide any
other legitimate date format eg

{ REF bDate \@ "YYYY/MM" }
{ REF bDate \@ "d MM yyyy" }

You might find it convenient to use a pop up calendar associated with an
autonew macro to select the initial date and avoid errors - see
http://www.gmayor.com/popup_calendar.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

giovanni

Thank you, that was very helpful. I do have another problem though: the
particular document I am working on is in French, though the OS and Office
are in English (most of my other documents are in English), so Word does not
recognise the French month names as valid dates (if I replace the French word
for the equivalent english one I have no problems). I tried setting French as
the default language for this particular template, but that did not affect
the result. Can I force the date to be in French? NOTE: I do have a French
dictionary and I can correctly insert date in French format.
 
G

Graham Mayor

If you use a REF field to reproduce the date and format that date field as
language = French then the formatting switches will insert the days and
months with their French language equivalents e.g.

{REF bDate \@ "dddd, d MMMM yyyy" } should produce
jeudi, 8 janvier 2009

Do the French capitalise their days and months? It's been a while ... but if
they do you can add a Caps switch

{ Date \@ "dddd, d MMMM yyyy" \*Caps }

to produce
Jeudi, 8 Janvier 2009

Probably even simpler where different languages are involved is to take my
previous suggestion of using the pop up calendar to collect the date
(assuming the initial date cannot be derived from a CreateDate field?) and
assign the result from the calendar to a docvariable. You can then use
docvariable fields FORMATTED WITH THE FRENCH language attribute, wherever
you want to insert the date e.g.

{ DOCVARIABLE varDate \@ "dddd d MMMM yyyy"}
{ DOCVARIABLE varDate \@ "d MMM yyyy"}
{ DOCVARIABLE varDate \@ " MM yyyy"}

to show
jeudi 8 janvier 2009

8 janv. 2009

01 2009


respectively.

The revised code associated with the calendar form to achieve that would be

Private Sub Calendar1_Click()
Dim oVars As Variables
Dim i As Long
Set oVars = ActiveDocument.Variables
oVars("varDate").Value = _
format(Calendar1.Value, "dd MM yyyy")
For i = ActiveDocument.Fields.Count To 1 Step -1
With ActiveDocument.Fields(i)
If .Type = wdFieldDocVariable Then .Update
End With
Next i
Unload Me
End Sub

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

giovanni

Thank you for your reply. The problem is not the formatting of the referenced
dates but of the input date: when I select a date such as "8 septembre 2006"
to bookmark it, Word is not recognizing "septembre" as a valid month even
though I selected the language for the document to be French. To have the
french word recognized as a valid month, I have to change the "Primary
Editing Language" to French under the Office 2007 Language Settings. However
this way all new documents are based on the French standard by default, while
I would like to do so only for the current document template. Do you have any
suggestions?
 
G

Graham Mayor

I have just given you a suggestion. Insert the date by macro and format the
document as French. Then you don't have to worry about the language format
of the date in the document as that date will be that inserted by the
macro/docvariable fields.
Your comments about septembre not being recognized by the REF field is not
limited to Word 2007 and I don't know of a way around it using the bookmark
method ... though you could use an ASK field to collect the date in a
numeric format eg dd\MM\yy. Picking the date from a calendar avoids
incorrect date insertion.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

giovanni

I am so sorry, I did not read your post fully and I did not see the calenda
pop up suggestion! My bad, thank you very much for your answer!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top