There are various possible ways to do it depending on what you are trying to
achieve, but in the general case I would probably favour the following
a. using a VBA routine to set up the texts you want in document variables
called day1, day2, ,day366. Once you have run that routine, the document can
be used for the year you specified
b. using a nested field like this in your header or footer:
{ DOCVARIABLE "day{ PAGE }" }
Sample VBA:
' A routine to set up 366 "daynnn" variables starting with date StartDate
' By doing 366 it doesn't matter whether it's a leap year or not
Sub SetUpDateVariables(StartDate As Date)
On Error Resume Next
For i = 1 To 366
ActiveDocument.Variables("day" & Trim(CStr(i))).Delete
ActiveDocument.Variables.Add _
Name:="day" & Trim(CStr(i)), _
Value:=Format(DateAdd("D", i - 1, StartDate), "MMM D, YYYY")
Next
End Sub
' A routine to set up the day variables for 2007
Sub setup2007()
Call SetUpDateVariables(#1/1/2007#)
End Sub
a. Put the macros in a module in your document or a suitable template
b. run setup2007. The variables are created and persist in your document
c. in your document, in a header or footer, use command-F9 to insert some
field code braces {}
d. type DOCVARIABLE "day" so you have
{ DOCVARIABLE "day" }
Put the insertion point just before the second double-quote and press
command-F9 again so you have
{ DOCVARIABLE "day{ }" }
type DATE between the new braces so you have
{ DOCVARIABLE "day{ DATE }" }
then update the field and verify that it works as you expect. Use the Page
Number Format icon in the header/footer toolbar to ensure that { PAGE }
returns a number and nothing else, and starts at 1.
You can probably do it all using fields but I think the docvariable approach
is a reasonably simple and maintanable solution.
Peter Jamieson