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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Want to increment date in Word header

Status
Not open for further replies.

gaysue

Technical User
Feb 3, 2004
1
US
I would like to start with a certain date and then increment it by one day in the header of a MS Word 2003 document. I have 48 pages and I would like the first page to start on the date I give it, then each page thereafter increment by one. How can I do that? I need it to do like page numbers do, except I want to tell it where to start.
 
Headers are properties of Sections. There are three possible Headers per Section:

Primary = the header for ALL pages, unless the following are set to True; in which case Primary becomes the header for odd pages.

First Page = a different header for the first page of the section.

EvenPages = header for the even pages.

As you can see, if you want a different header for EACH page of a 48 page document, you must make separate sections for each page. Until you do that you can NOT have different headers for all 48 pages.

1. You may want to consider a separate text area for each page. Unfortunately, as Word paginates dynamically, this could easily move that text area on to the wrong page. Not a good solution.

2. Make separate sections for each page. This also has problems. Depending on how much text may come in and out, editing may adjust pagination and again set things off.

That being said, you simply insert a date, as a Date data type and increment it by 1. Look up date in Help, also look up Format for ways to display dates. Here is a little snippet that displays incremented dates (six days added to the original which I arbitrarily made Feb 4) in a messagebox. Good luck!

Code:
Sub IncrementDate()
Dim StartDate As Date
Dim i As Integer
Dim var
Dim msg As String

StartDate = "February 4, 2005"
i = 1

msg = Format(StartDate, "long date")
    For var = 1 To 6
        msg = msg & vbCrLf & _
              Format(StartDate + i, "long date")
        i = i + 1
    Next
MsgBox msg
End Sub

Gerry
 
I think this is not practical. As Gerry says, the header is associated with sections and you don't want a section for every page.

Ideally the solution would have been to find a suitable field code that could be placed in a heading. I did wonder whether you could have a page number field formatted to appear like a date but

a) you can't
b) even if you could the maximum page number is around 32k which is not enough for a current date measured as days since 1900.

The only other possibility is to have a macro that prints one page at a time and alters the header before each page. You would need to be sure that the amount of text in the header would not affect pagination but if it's just a date that should not be a problem. By definition, you could never get a true print preview.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top