Sequential Dates

D

dbunhook

Hi. I am creating an itinerary for a trip my club will be taking this summer.
Each page has a heading "Day 1 - Tuesday, May 1" and will go on to list the
things we will be doing that day. I know how to automatically number the
days. I would like to be able to generate the dates as well based on a start
date. The dates are all sequential. Is there a way to do that in Word?
 
G

Greg

dbunhook

Sub DateSeq()
Dim myDate As Date
Dim dayNum As Long
Dim numDays As Long

myDate = InputBox("Enter the start date in 1/31/2005 format.", "Start
On", Date)
numDays = InputBox("Enter the sequence length in days.", "Sequence
Length", "14")
For dayNum = 0 To numDays
ActiveDocument.Variables("Var" & dayNum).Value = Format(myDate +
dayNum - 1, "dddd, mmm d yyyy")
Next
ActiveDocument.Fields.Update
End Sub


Run the macro DateSeq() to set start date and length. DateSeq() then
creates DocVariables Val1 thorough Val(numDays) which stores the
sequenced date.

In the document, insert the DocVariables using:

{ DocVariable{ Quote Var{ Seq dayNum }}

You can then copy and paste this field code to create a date sequence
in a document similar to any numbered sequence using the SEQ fie
Thanks for the challenge
 
D

dbunhook

I got the macro working to create the document variables but am having
trouble inserting them into the document.

I can insert field code: {DocVariable "Var1"} and get the dates inserted.
But the problem is that I have to name each DocVariable (i.e., Var1, Var2,
Var3). This would not allow me to move sections around and have them
renumbered and re-dated in sequence.

Your example suggested I insert this {DocVariable{ Quote Var{Seq dayNum}},
which seemed the right thing to do. However, when I tried this, I got the
error message "Error! No document variable suppled.".

Any suggestions on where to go next?
 
G

Greg Maxey

dbunhook,

My example was missing a bracket. My apologies. That is a problem when
trying to duplicate field code as free text.

{ DocVariable{ Quote Var{ Seq Date }}}

It is a basic SEQ field (I have since decided to name the sequence date)
nested in a Quote field neste in the a docvarialble field.

It should work with this change.
 
G

Greg Maxey

BTW, once you have the the DocVarialbe field working, you can select the
result, press ALT+F3 and name a AutoText entry (i.e. nextday). Anytime you
want the next date in the sequence just tryp next.. and when the
autocomplete tip pops up press enter.
 
D

dbunhook

Thank you Greg. It took me awhile but I finally figured out that you have to
use Ctrl-F9 to insert the curly brackets that Word identifies as a field code.

Thank for your help. This works like a charm.
 
G

Greg Maxey

dbunhook,

I could have told you that. I assumed that since you where already using
SEQ fields for the day numbers that you knew it already.
 
J

Jennifer D.

That macro is very helpful and works wonderfully. I was wondering, though,
if it was possible to make a particular modification to it.

I am working with a document that will have a date on each page, but I don't
want the dates to be sequential. I actually want the dates to be 7 days
apart from eachother. For example, I want the first page to refer to
Monday, February 14, 2005, the second to refer to Monday, Febrary 21, 2005,
the third to refer to Monday, February 28, 2005, etc.

What would I need to change to make this possible?

Any help is appreciated.
 
G

Greg Maxey

Jennifer,

You will want to use the the Sequenced AutoText output, Period "week,"
Factor "1" (or Period "day" Factor "7"). In the number field enter a value
that will provide enough docVariables for you application (i.e., the number
of pages that you expect) the default is 50.
 
G

Greg

If you want to stick with the macro, then change the formula from
= Format(myDate + dayNum - 1 to
= Format(myDate + 7 * (dayNum - 1)
 

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