Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Sunrise, Florida
    Posts
    324
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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. #2
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    La Jolla, CA
    Posts
    1,470
    Thanks
    30
    Thanked 62 Times in 58 Posts

    Re: Working with days

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

  3. #3
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    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>

    Andrew Lockton, Chrysalis Design, Melbourne Australia

  4. #4
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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>



    Hope that can help you

    Andrew C

  5. #5
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Sunrise, Florida
    Posts
    324
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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
  •