Create Sequential Dates

G

Greg

Hello Teachers,

Today I spent some time trying to come up with a way to enter a
sequence of dates in a document. Basically the OP had an Itenerary

Day 1 Jan 07, 2005
Day 2 Jan 08, 2005
etc.

I posted a solution where the user would run a macro to create a
collection of numbered DocVariables each storing the next days date.
Then in the document I inserted DocVariable fields with nested Quote
and Seq fields.

Day {Seq Date} { DocVariable{ Quote Var{ Seq dayNum }}
Day {Seq Date} { DocVariable{ Quote Var{ Seq dayNum }}
etc.

The macro to create the DocVariables follows:

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

I looked through the Google data base for anything close and didn't
seeing anything. This seems to work, but I am to declare victory. I
would appreaciate any comments on this method or suggestions for a
better method.

Thanks
 
H

Helmut Weber

Hi Greg,

I got no idea, what doc-variables are good for here,
and I hate fields anyway. I can do without them.

Sub Test001()
Dim i As Integer ' just a counter
Dim DDiff As Integer ' interval date difference
Dim DStps As Integer ' steps to go
Dim Start As Date ' the start date
Start = InputBox("Start dd.mm.yyyy") ' german
' no check provided
DDiff = InputBox("Interval")
DStps = InputBox("Steps")
Selection.TypeText Text:=Start & vbCr
For i = DDiff To DStps * DDiff Step DDiff
Selection.TypeText Text:=Format(Start + i, "dd.mm.yyyy") & vbCr
It's up to you where to insert the calculated date
Next
End Sub

Greetings from Bavaria,
a region in Europe,
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
G

Greg Maxey

Helmut,

Interesting. Thanks.

The OP that I was helping apparently puts together interaries for his/her
travel club.

Apparently they are laid out

Day 1 Jan 1 2005
Do this
Day 2 Jan 2 2005
Do that
etc.

Uses SEQ fields to create the day number and was looking for a way to use a
similiar sequence for the date so that if Day2 was moved above Day1 a fields
update would sort out both day number and date. The only thing I could
think of was to store the sequence of dates in numbered docvarialbes Var1
Var2 etc. and then display those dates in as sequenced docvariable fields.
 

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