Automatic numbering by dates

Ã

Øystein

I have a row of cells which is a part of a bigger word document. In this row
I want to write a date in the cell to the left (e.g. by using "fill in
fields" and then automaticly calculate the date of the day after in the next
cell and so on.
 
D

Doug Robbins - Word MVP

With the cursor in the cell into which the start date is to be inserted, run
a macro containing the following code:

Dim i As Long, j As Long
Dim atable As Table
Dim StartDate As Date
Set atable = Selection.Tables(1)
i = Selection.Information(wdEndOfRangeRowNumber)
StartDate = InputBox("Enter the start Date in the format dd/MM/yyyy.")
atable.Cell(i, 1).Range = Format(StartDate, "dd/MM/yyyy")
For j = 2 To atable.Columns.Count
atable.Cell(i, j).Range = Format(DateAdd("d", j - 1, StartDate),
"dd/MM/yyyy")
Next j


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

" Øystein <[email protected]>" <=?UTF-8?Q? =C3=98ystein
 
M

macropod

Hi Øystein,

Here's another way to do this:

First, download my Date Calc 'tutorial', at:
http://www.wopr.com/cgi-bin/w3t/showthreaded.pl?Number=249902

Next, copy the field under the heading 'Calculate a day, date, month and
year, using n (301) days delay' and paste into your document where you want
the first calculated date to appear.

Next, press Alt-F9 to expose the field coding, then change each instance of
'DATE' to 'StartDate' and 'SET Delay 301' to 'SET Delay 1'.

Next, copy the field coding, to each of the other cells you want dates to
appear in, incrementing the value in the 'SET Delay ' field.

Then press Alt-F9 again to hide the field coding

Now, at the location where where your first date is to appear, insert a
FILLIN field to solicit that date. Bookmark the field, naming it
'StartDate'.

Finally, select the table and press F9 to initiate the field calculations.

Note that simply updating the FILLIN field isn't enough to force the other
fields to recalculate. You can automate the FILLIN prompt and recalculation
at printtime if you check the 'update fields' option under
Tools|Options|Print.

Alternatively, if automatic recalculation at the time of data entry is
important, you could use a Word formfield at the location where where your
first date is to appear. After inserting the formfield, right-click it to
access its options. Set the 'Type' to 'Date' and set the 'Format' to
whatever you're using. Give the formfield the 'StartDate' bookmark and set
it to 'calculate on exit'. If your users need to be able to type freely in
other cells, they'll need their own formfields for this and, if your users
need to be able to type freely elsewhere in the document, you'll need
Section breaks before and/or after the table. Once you've done this, protect
the document for forms via Tools|Prtoect Document|Forms and select the
Section containing the table for protection.

Cheers
 

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