Reply
 
Thread Tools Display Modes
  #1   Report Post  
Thomas M
 
Posts: n/a
Default Date Formula in a Field

Word 2000

I have a weekly status report document that contains the following
information in the heading:

Report Period: April 4 to April 8, 2005

I'd like to insert fields into the heading so that the first date is always
for Monday of the current week, and the second date is always Friday of the
current week. I know how to insert basic fields, but I don't know how to
get this fancy will fields and formulas in Word. Any ideas?

--Tom


  #2   Report Post  
Charles Kenyon
 
Posts: n/a
Default

See http://www.wopr.com/cgi-bin/w3t/show...&Number=249902
and http://addbalance.com/word/datefields2.htm. This is more complex than
you imagine.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

"Thomas M" wrote in message
...
Word 2000

I have a weekly status report document that contains the following
information in the heading:

Report Period: April 4 to April 8, 2005

I'd like to insert fields into the heading so that the first date is
always
for Monday of the current week, and the second date is always Friday of
the
current week. I know how to insert basic fields, but I don't know how to
get this fancy will fields and formulas in Word. Any ideas?

--Tom




  #3   Report Post  
Thomas M
 
Posts: n/a
Default

Thanks for the reply. Sorry that it took me so long to respond on this, but
frankly, I forgot about the issue until I opened my file today. While I
didn't know how to accomplish this in the way that I originally posed the
question, I knew enough about fields and date handling in Word to know that
it probably would not be easy.

I clicked on the first link that you posted, and the resulting article
mentioned working with macros. I don't know why I didn't think of that
before, but it occurred to me that I could write a macro to put the
necessary values into some document variables, and then insert some
formatted fields that refer to those document variables. Here's the macro
that I wrote:

Private Sub Document_Open()

Dim EndDate As Date
Dim StartDate As Date

' Calculates the StartDate and EndDate values.
StartDate = Date - (Weekday(Date) - vbMonday)
EndDate = Date - (vbFriday - Weekday(Date))

' Writes the StartDate and EndDate values to document variables that are
used in the document heading.
ActiveDocument.Variables("StartDate").Value = StartDate
ActiveDocument.Variables("EndDate").Value = EndDate

' Updates the fields in the document.
ActiveDocument.Fields.Update

End Sub

I'll probably add a check for the document variables so that if they ever
get deleted somehow, the code will recreate them instead of just crashing.
In the document I put the following:

Report Period: { DOCVARIABLE "StartDate" \*MERGEFORMAT "MMMM DD, YYYY" }
to
{ DOCVARIABLE "EndDate" \*MERGEFORMAT "MMMM DD, YYYY" }

It seems to work well, but thus far I've only tested it on a Friday, so I'm
not 100% certain that there isn't a bug in the code.

--Tom

"Charles Kenyon" wrote in
message ...
See

http://www.wopr.com/cgi-bin/w3t/show...&Number=249902
and http://addbalance.com/word/datefields2.htm. This is more complex than
you imagine.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

"Thomas M" wrote in message
...
Word 2000

I have a weekly status report document that contains the following
information in the heading:

Report Period: April 4 to April 8, 2005

I'd like to insert fields into the heading so that the first date is
always
for Monday of the current week, and the second date is always Friday of
the
current week. I know how to insert basic fields, but I don't know how

to
get this fancy will fields and formulas in Word. Any ideas?

--Tom






  #4   Report Post  
Charles Kenyon
 
Posts: n/a
Default

The second article gives several sample macros that have been tested. There
are more on Graham Mayor's site.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

"Thomas M" wrote in message
...
Thanks for the reply. Sorry that it took me so long to respond on this,
but
frankly, I forgot about the issue until I opened my file today. While I
didn't know how to accomplish this in the way that I originally posed the
question, I knew enough about fields and date handling in Word to know
that
it probably would not be easy.

I clicked on the first link that you posted, and the resulting article
mentioned working with macros. I don't know why I didn't think of that
before, but it occurred to me that I could write a macro to put the
necessary values into some document variables, and then insert some
formatted fields that refer to those document variables. Here's the macro
that I wrote:

Private Sub Document_Open()

Dim EndDate As Date
Dim StartDate As Date

' Calculates the StartDate and EndDate values.
StartDate = Date - (Weekday(Date) - vbMonday)
EndDate = Date - (vbFriday - Weekday(Date))

' Writes the StartDate and EndDate values to document variables that
are
used in the document heading.
ActiveDocument.Variables("StartDate").Value = StartDate
ActiveDocument.Variables("EndDate").Value = EndDate

' Updates the fields in the document.
ActiveDocument.Fields.Update

End Sub

I'll probably add a check for the document variables so that if they ever
get deleted somehow, the code will recreate them instead of just crashing.
In the document I put the following:

Report Period: { DOCVARIABLE "StartDate" \*MERGEFORMAT "MMMM DD,
YYYY" }
to
{ DOCVARIABLE "EndDate" \*MERGEFORMAT "MMMM DD, YYYY" }

It seems to work well, but thus far I've only tested it on a Friday, so
I'm
not 100% certain that there isn't a bug in the code.

--Tom

"Charles Kenyon" wrote in
message ...
See

http://www.wopr.com/cgi-bin/w3t/show...&Number=249902
and http://addbalance.com/word/datefields2.htm. This is more complex than
you imagine.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

"Thomas M" wrote in message
...
Word 2000

I have a weekly status report document that contains the following
information in the heading:

Report Period: April 4 to April 8, 2005

I'd like to insert fields into the heading so that the first date is
always
for Monday of the current week, and the second date is always Friday of
the
current week. I know how to insert basic fields, but I don't know how

to
get this fancy will fields and formulas in Word. Any ideas?

--Tom








  #5   Report Post  
Thomas M
 
Posts: n/a
Default

It turns out that there was an error in my code. If the current date is a
Monday, the EndDate would not calculate correctly. I believe that the
following code will work for all weekdays (but I've only tested it for
Monday thus far).

Private Sub Document_Open()

Dim EndDate As Date
Dim StartDate As Date

' Calculates the StartDate and EndDate values.
StartDate = Date - (Weekday(Date) - vbMonday)
EndDate = StartDate + 4

' Writes the StartDate and EndDate values to document variables that are
used in the document heading.
ActiveDocument.Variables("StartDate").Value = StartDate
ActiveDocument.Variables("EndDate").Value = EndDate

' Updates the fields in the document.
ActiveDocument.Fields.Update

End Sub

--Tom

"Thomas M" wrote in message
...
Thanks for the reply. Sorry that it took me so long to respond on this,

but
frankly, I forgot about the issue until I opened my file today. While I
didn't know how to accomplish this in the way that I originally posed the
question, I knew enough about fields and date handling in Word to know

that
it probably would not be easy.

I clicked on the first link that you posted, and the resulting article
mentioned working with macros. I don't know why I didn't think of that
before, but it occurred to me that I could write a macro to put the
necessary values into some document variables, and then insert some
formatted fields that refer to those document variables. Here's the macro
that I wrote:

Private Sub Document_Open()

Dim EndDate As Date
Dim StartDate As Date

' Calculates the StartDate and EndDate values.
StartDate = Date - (Weekday(Date) - vbMonday)
EndDate = Date - (vbFriday - Weekday(Date))

' Writes the StartDate and EndDate values to document variables that

are
used in the document heading.
ActiveDocument.Variables("StartDate").Value = StartDate
ActiveDocument.Variables("EndDate").Value = EndDate

' Updates the fields in the document.
ActiveDocument.Fields.Update

End Sub

I'll probably add a check for the document variables so that if they ever
get deleted somehow, the code will recreate them instead of just crashing.
In the document I put the following:

Report Period: { DOCVARIABLE "StartDate" \*MERGEFORMAT "MMMM DD,

YYYY" }
to
{ DOCVARIABLE "EndDate" \*MERGEFORMAT "MMMM DD, YYYY" }

It seems to work well, but thus far I've only tested it on a Friday, so

I'm
not 100% certain that there isn't a bug in the code.

--Tom

"Charles Kenyon" wrote in
message ...
See

http://www.wopr.com/cgi-bin/w3t/show...&Number=249902
and http://addbalance.com/word/datefields2.htm. This is more complex

than
you imagine.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

"Thomas M" wrote in message
...
Word 2000

I have a weekly status report document that contains the following
information in the heading:

Report Period: April 4 to April 8, 2005

I'd like to insert fields into the heading so that the first date is
always
for Monday of the current week, and the second date is always Friday

of
the
current week. I know how to insert basic fields, but I don't know how

to
get this fancy will fields and formulas in Word. Any ideas?

--Tom








Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
using date field in merge Henri Vrancken Mailmerge 3 March 5th 05 01:52 PM
Updating a date field LDHardy Microsoft Word Help 2 February 25th 05 04:07 PM
How to prevent Merged Date Field showing time? jmasood Mailmerge 1 February 21st 05 11:59 AM
inserting a date field for a future date rm Microsoft Word Help 2 January 10th 05 07:18 PM
Date issue merging from Excel field in Date format to Word Barb Reinhardt Mailmerge 1 December 17th 04 07:34 AM


All times are GMT +1. The time now is 09:04 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"