1. ## Working with days

I use Word 97. Need help with the following. I'll give a date to Word through a macro. I need Word to determine the month that date belongs to and tell me the date for a particular day (i.e. the second Tuesday in that month). Any help appreciated.

2. ## Re: Working with days

Word doesn't handle date calculations. I suggest you try Excel for this.

3. ## Re: Working with days

Here's a macro which show the barebones of what you want to do. You will have do a bunch of stuff to it to fit your end purpose but it should be reasonably logical to follow. You may want a different algorithm to sort out the nth day of a month such as
date = date + ((n-1)*7)
<pre>Sub Macro2()
Dim dDate As Date, sMonth As String, d2Date As Date, n As Long
Dim sYear As String, SecondTuesday As String
Dim sDay As String, sFindDay As String
dDate = Now()
sMonth = Format(dDate, "MMMM")
sYear = Format(dDate, "YYYY")
sDay = Format(dDate, "dddd")
For n = 1 To 7
d2Date = DateValue(n & "/" & sMonth & "/" & sYear)
sFindDay = Format(d2Date, "dddd")
If sFindDay = "Tuesday" Then Exit For
Next n
SecondTuesday = d2Date + 7
MsgBox "Today is: " & sDay & " " & sMonth & " " & sYear & vbCr & _
"The second Tuesday for this month is: " & SecondTuesday
End Sub</pre>

4. ## Re: Working with days

Actually, though word may not be good at calculating dates, VBA can do a reasonable job.
The following 2 functions should give you a way to get what you are looking for.

1. Return the month of a given date
<pre> Function DateMonth(d As String) As Variant
DateMonth = Format(DateValue(d), "mmmm")
End Function</pre>

2. Return the next day of week of a given date
<pre> Function NextDay(d As String, day As Integer) As Variant
Dim TestDay As Date
TestDay = DateValue(d) + 1
Do Until Weekday(TestDay) = day
TestDay = TestDay + 1
Loop
NextDay = Format(TestDay, "ddd mmmm dd")
End Function</pre>

A little routine to test the above
<pre> Sub TestNextDay()
x = NextDay("03/04/2001", 3)
y = DateMonth("03/04/2001")
Debug.Print x
Debug.Print y
End Sub</pre>

Andrew C

5. ## Re: Working with days

I want to thank kweaver, Andrew Lockton and Andrew Connolly for their help. Thanks to them I was able to achieve my goal!

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•