Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
v&sr4JC v&sr4JC is offline
external usenet poster
 
Posts: 3
Default macro to calculate a date in the future

I would like to have a macro that would calculate a date in the future. I
need to include in my letters for work that a response is due within 8 days.
So 8 days from the date of my letter, I would like a toolbar macro that will
input the date, 8 days in the future but if that date falls on a weekend, it
would select Monday as the due date. Is this possible?
--
many thanks,
Sally
  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Greg Maxey Greg Maxey is offline
external usenet poster
 
Posts: 171
Default macro to calculate a date in the future

Sally,

Not very elegant and assumes the date of the letter is in a bookmark
named "DOL" and the location of the due date is bookmarked "DD"

Sub Test()
Dim oRng As Range
Dim dateDOL As Date
Dim dateDD As Date
dateDOL = CDate(ActiveDocument.Bookmarks("DOL").Range.Text)
dateDD = DateAdd("d", 8, dateDOL)
Select Case Format(dateDD, "DDDD")
Case "Saturday"
dateDD = DateAdd("d", 2, dateDD)
Case "Sunday"
dateDD = DateAdd("d", 1, dateDD)
Case Else
'Do Nothing
End Select
Set oRng = ActiveDocument.Bookmarks("DD").Range
oRng.Text = dateDD
ActiveDocument.Bookmarks.Add "DD", oRng
End Sub




v&sr4JC wrote:
I would like to have a macro that would calculate a date in the future. I
need to include in my letters for work that a response is due within 8 days.
So 8 days from the date of my letter, I would like a toolbar macro that will
input the date, 8 days in the future but if that date falls on a weekend, it
would select Monday as the due date. Is this possible?
--
many thanks,
Sally


  #3   Report Post  
Posted to microsoft.public.word.docmanagement
v&sr4JC v&sr4JC is offline
external usenet poster
 
Posts: 3
Default macro to calculate a date in the future

Where can I find a good explanation on these bookmarks and would they work on
letters that are automatically generated by our database system?
--
many thanks,
Sally



  #4   Report Post  
Posted to microsoft.public.word.docmanagement
Suzanne S. Barnhill Suzanne S. Barnhill is offline
external usenet poster
 
Posts: 33,624
Default macro to calculate a date in the future

See http://www.gmayor.com/insert_a_date_...than_today.htm

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
Word MVP FAQ site: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

"v&sr4JC" wrote in message
...
I would like to have a macro that would calculate a date in the future. I
need to include in my letters for work that a response is due within 8

days.
So 8 days from the date of my letter, I would like a toolbar macro that

will
input the date, 8 days in the future but if that date falls on a weekend,

it
would select Monday as the due date. Is this possible?
--
many thanks,
Sally


  #5   Report Post  
Posted to microsoft.public.word.docmanagement
Greg Maxey Greg Maxey is offline
external usenet poster
 
Posts: 171
Default macro to calculate a date in the future

Sally,

A bookmark is just a spot marked in your document. It can be a single
spot (i.e., the insertion point) or span a range of text.

For my example code I gave you, I opened a new blank document;

Typed in today's date;
Selected the date and used InsertBookmark to bookmark that text as
"DOL." DOL is just an arbitrary name I used to identify the bookmark.
Next I put the cursor down a few lines and inserted another bookmark
"DD." The bookmark DD identifies the place in the document to insert
the due date. Again DD is just an arbitrary name I used to stand in
for due date.

Whether it works with your letters generated from your data base is up
to you. The concept is:

Get the date from somewhere (e.g., a field, bookmark, input box, the
selection)
Send it through the mill to convert that date to a due date that meets
your requiremetns
Write that revised date to somewhere in the document.

HTH
v&sr4JC wrote:
Where can I find a good explanation on these bookmarks and would they work on
letters that are automatically generated by our database system?
--
many thanks,
Sally




  #6   Report Post  
Posted to microsoft.public.word.docmanagement
Greg Maxey Greg Maxey is offline
external usenet poster
 
Posts: 171
Default macro to calculate a date in the future

Suzanne,

Unless I missed it, I don't think Graham's method would bump the due
date to Monday if it normally would fall on the weekend.


Suzanne S. Barnhill wrote:
See http://www.gmayor.com/insert_a_date_...than_today.htm

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
Word MVP FAQ site: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

"v&sr4JC" wrote in message
...
I would like to have a macro that would calculate a date in the future. I
need to include in my letters for work that a response is due within 8

days.
So 8 days from the date of my letter, I would like a toolbar macro that

will
input the date, 8 days in the future but if that date falls on a weekend,

it
would select Monday as the due date. Is this possible?
--
many thanks,
Sally


  #7   Report Post  
Posted to microsoft.public.word.docmanagement
v&sr4JC v&sr4JC is offline
external usenet poster
 
Posts: 3
Default macro to calculate a date in the future

Super! I got it to work. Is there a way I can make the date automatically
appear in bold?
--
many thanks,
Sally



  #8   Report Post  
Posted to microsoft.public.word.docmanagement
Greg Maxey Greg Maxey is offline
external usenet poster
 
Posts: 171
Default macro to calculate a date in the future

Yes,

Sub Test()
Dim oRng As Range
Dim dateDOL As Date
Dim dateDD As Date
dateDOL = CDate(ActiveDocument.Bookmarks("DOL").Range.Text)
dateDD = DateAdd("d", 8, dateDOL)
Select Case Format(dateDD, "DDDD")
Case "Saturday"
dateDD = DateAdd("d", 2, dateDD)
Case "Sunday"
dateDD = DateAdd("d", 1, dateDD)
Case Else
'Do Nothing
End Select
Set oRng = ActiveDocument.Bookmarks("DD").Range
With oRng
.Text = dateDD
.Font.Bold = True
End With
ActiveDocument.Bookmarks.Add "DD", oRng
End Sub




v&sr4JC wrote:
Super! I got it to work. Is there a way I can make the date automatically
appear in bold?
--
many thanks,
Sally


  #9   Report Post  
Posted to microsoft.public.word.docmanagement
sandy sandy is offline
external usenet poster
 
Posts: 58
Default macro to calculate a date in the future

This looks like something that will help me too. But how or where to I
reference this macro in my document? Do I tell the DOL properties to run
this macro on exit or ???

Thanks in advance.

"Greg Maxey" wrote:

Sally,

Not very elegant and assumes the date of the letter is in a bookmark
named "DOL" and the location of the due date is bookmarked "DD"

Sub Test()
Dim oRng As Range
Dim dateDOL As Date
Dim dateDD As Date
dateDOL = CDate(ActiveDocument.Bookmarks("DOL").Range.Text)
dateDD = DateAdd("d", 8, dateDOL)
Select Case Format(dateDD, "DDDD")
Case "Saturday"
dateDD = DateAdd("d", 2, dateDD)
Case "Sunday"
dateDD = DateAdd("d", 1, dateDD)
Case Else
'Do Nothing
End Select
Set oRng = ActiveDocument.Bookmarks("DD").Range
oRng.Text = dateDD
ActiveDocument.Bookmarks.Add "DD", oRng
End Sub




v&sr4JC wrote:
I would like to have a macro that would calculate a date in the future. I
need to include in my letters for work that a response is due within 8 days.
So 8 days from the date of my letter, I would like a toolbar macro that will
input the date, 8 days in the future but if that date falls on a weekend, it
would select Monday as the due date. Is this possible?
--
many thanks,
Sally



  #10   Report Post  
Posted to microsoft.public.word.docmanagement
macropod[_2_] macropod[_2_] is offline
external usenet poster
 
Posts: 2,059
Default macro to calculate a date in the future

Hi Sandy,

For a solution to this and just about everything else you might want to do with dates in Word (all done without macros), check out
my Date Calc 'tutorial', at:
http://www.wopr.com/cgi-bin/w3t/show...?Number=249902
or
http://www.gmayor.com/downloads.htm#Third_party
In particular, look at the item titled 'Handling Weekends and Holidays in Calculated Dates'. Do read the document's introductory
material.

--
Cheers
macropod
[MVP - Microsoft Word]


"Sandy" wrote in message ...
This looks like something that will help me too. But how or where to I
reference this macro in my document? Do I tell the DOL properties to run
this macro on exit or ???

Thanks in advance.

"Greg Maxey" wrote:

Sally,

Not very elegant and assumes the date of the letter is in a bookmark
named "DOL" and the location of the due date is bookmarked "DD"

Sub Test()
Dim oRng As Range
Dim dateDOL As Date
Dim dateDD As Date
dateDOL = CDate(ActiveDocument.Bookmarks("DOL").Range.Text)
dateDD = DateAdd("d", 8, dateDOL)
Select Case Format(dateDD, "DDDD")
Case "Saturday"
dateDD = DateAdd("d", 2, dateDD)
Case "Sunday"
dateDD = DateAdd("d", 1, dateDD)
Case Else
'Do Nothing
End Select
Set oRng = ActiveDocument.Bookmarks("DD").Range
oRng.Text = dateDD
ActiveDocument.Bookmarks.Add "DD", oRng
End Sub




v&sr4JC wrote:
I would like to have a macro that would calculate a date in the future. I
need to include in my letters for work that a response is due within 8 days.
So 8 days from the date of my letter, I would like a toolbar macro that will
input the date, 8 days in the future but if that date falls on a weekend, it
would select Monday as the due date. Is this possible?
--
many thanks,
Sally






  #11   Report Post  
Posted to microsoft.public.word.docmanagement
qldlifestyle qldlifestyle is offline
external usenet poster
 
Posts: 2
Default macro to calculate a date in the future

Greg This is brilliant. However I'm still haveing trouble with it.
When I try to run it I get a "Type Mismatch" message box.
I copied and pasted the macro.
Could you tell me what I have done wrong.

"Greg Maxey" wrote:

Sally,

Not very elegant and assumes the date of the letter is in a bookmark
named "DOL" and the location of the due date is bookmarked "DD"

Sub Test()
Dim oRng As Range
Dim dateDOL As Date
Dim dateDD As Date
dateDOL = CDate(ActiveDocument.Bookmarks("DOL").Range.Text)
dateDD = DateAdd("d", 8, dateDOL)
Select Case Format(dateDD, "DDDD")
Case "Saturday"
dateDD = DateAdd("d", 2, dateDD)
Case "Sunday"
dateDD = DateAdd("d", 1, dateDD)
Case Else
'Do Nothing
End Select
Set oRng = ActiveDocument.Bookmarks("DD").Range
oRng.Text = dateDD
ActiveDocument.Bookmarks.Add "DD", oRng
End Sub




v&sr4JC wrote:
I would like to have a macro that would calculate a date in the future. I
need to include in my letters for work that a response is due within 8 days.
So 8 days from the date of my letter, I would like a toolbar macro that will
input the date, 8 days in the future but if that date falls on a weekend, it
would select Monday as the due date. Is this possible?
--
many thanks,
Sally



  #12   Report Post  
Posted to microsoft.public.word.docmanagement
Greg Maxey[_2_] Greg Maxey[_2_] is offline
external usenet poster
 
Posts: 668
Default macro to calculate a date in the future

I suspect that you don't have the date of the letter bookmarked correctly or
you don't have a valid date in the bookmark.

Type 05 February 2009 in the document. Select it and then bookmark the
selection as DOL. Create another bookmark at the IP where the future date
should appear. Name it DD.

Run the code.


qldlifestyle wrote:
Greg This is brilliant. However I'm still haveing trouble with it.
When I try to run it I get a "Type Mismatch" message box.
I copied and pasted the macro.
Could you tell me what I have done wrong.

"Greg Maxey" wrote:

Sally,

Not very elegant and assumes the date of the letter is in a bookmark
named "DOL" and the location of the due date is bookmarked "DD"

Sub Test()
Dim oRng As Range
Dim dateDOL As Date
Dim dateDD As Date
dateDOL = CDate(ActiveDocument.Bookmarks("DOL").Range.Text)
dateDD = DateAdd("d", 8, dateDOL)
Select Case Format(dateDD, "DDDD")
Case "Saturday"
dateDD = DateAdd("d", 2, dateDD)
Case "Sunday"
dateDD = DateAdd("d", 1, dateDD)
Case Else
'Do Nothing
End Select
Set oRng = ActiveDocument.Bookmarks("DD").Range
oRng.Text = dateDD
ActiveDocument.Bookmarks.Add "DD", oRng
End Sub




v&sr4JC wrote:
I would like to have a macro that would calculate a date in the
future. I need to include in my letters for work that a response
is due within 8 days. So 8 days from the date of my letter, I would
like a toolbar macro that will input the date, 8 days in the future
but if that date falls on a weekend, it would select Monday as the
due date. Is this possible? --
many thanks,
Sally


--
Greg Maxey - Word MVP

My web site http://gregmaxey.mvps.org
Word MVP web site http://word.mvps.org



  #13   Report Post  
Posted to microsoft.public.word.docmanagement
qldlifestyle qldlifestyle is offline
external usenet poster
 
Posts: 2
Default macro to calculate a date in the future

Thank you for your quick reply.
My error seems to have been with the bookmark, DOL and the formatting of the
date in the bookmark - "dddd, d MMMM yyyy". I removed the dddd and it worked.

"Greg Maxey" wrote:

I suspect that you don't have the date of the letter bookmarked correctly or
you don't have a valid date in the bookmark.

Type 05 February 2009 in the document. Select it and then bookmark the
selection as DOL. Create another bookmark at the IP where the future date
should appear. Name it DD.

Run the code.


qldlifestyle wrote:
Greg This is brilliant. However I'm still haveing trouble with it.
When I try to run it I get a "Type Mismatch" message box.
I copied and pasted the macro.
Could you tell me what I have done wrong.

"Greg Maxey" wrote:

Sally,

Not very elegant and assumes the date of the letter is in a bookmark
named "DOL" and the location of the due date is bookmarked "DD"

Sub Test()
Dim oRng As Range
Dim dateDOL As Date
Dim dateDD As Date
dateDOL = CDate(ActiveDocument.Bookmarks("DOL").Range.Text)
dateDD = DateAdd("d", 8, dateDOL)
Select Case Format(dateDD, "DDDD")
Case "Saturday"
dateDD = DateAdd("d", 2, dateDD)
Case "Sunday"
dateDD = DateAdd("d", 1, dateDD)
Case Else
'Do Nothing
End Select
Set oRng = ActiveDocument.Bookmarks("DD").Range
oRng.Text = dateDD
ActiveDocument.Bookmarks.Add "DD", oRng
End Sub




v&sr4JC wrote:
I would like to have a macro that would calculate a date in the
future. I need to include in my letters for work that a response
is due within 8 days. So 8 days from the date of my letter, I would
like a toolbar macro that will input the date, 8 days in the future
but if that date falls on a weekend, it would select Monday as the
due date. Is this possible? --
many thanks,
Sally


--
Greg Maxey - Word MVP

My web site http://gregmaxey.mvps.org
Word MVP web site http://word.mvps.org




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
Need macro to locate table uniquely, insert blank row and date and end table Marrick13 Tables 4 July 1st 06 12:33 PM
How to calculate a Future Date? ToniEPC New Users 1 May 22nd 06 04:11 PM
In Word 2002 can I calculate a future date (Today + 7 days) ketilla Microsoft Word Help 3 May 16th 06 07:02 AM
How to calculate Future Dates? designgeek Microsoft Word Help 4 April 7th 06 12:43 PM
inserting a date field for a future date rm Microsoft Word Help 2 January 10th 05 07:18 PM


All times are GMT +1. The time now is 05:50 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"