+ Reply to Thread
Results 1 to 6 of 6

Need help with date macro

  1. #1
    Registered User
    Join Date
    08-09-2012
    Location
    Norfolk,va
    MS-Off Ver
    Excel 2007
    Posts
    15

    Need help with date macro

    I have a word document i am trying to input a macro for. i have setup a field in the top left to auto update with the date when you open the document. A few lines down is a line telling the monday - friday dates that report is covering (ex. 1 May 2013- 5 May 2013). The report is done every week. I am looking to write a macro to update those dates. i am not sure if i can make those dates in one field or two more fields. Thank you for your help.

  2. #2
    Registered User
    Join Date
    08-09-2012
    Location
    Norfolk,va
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Need help with date macro

    I did some more looking and found some info that helped. I am sure there is a way to add the to macro's together and insert it into the text string.
    The text string is "Subj: WEEKLY TRAINING FOR 4/29/2013(macro 1) – 5/3/2013.(macro 2)" i need to change the format of the date as well which is kicking my but currently. my 2 current macro's are.

    Macro 1
    Sub ReturnCurrentMonday()
    '
    'Return Monday of current week.
    '
    '
    Dim dteMonday As Date
    dteMonday = IIf(Weekday(Date) = 1, Date - 6, _
    Date - (Weekday(Date) - 2))
    Selection.InsertBefore (dteMonday)
    End Sub

    Macro 2
    Sub ReturnCurrentFriday()
    '
    'Return Friday of current week.
    '
    '
    Dim DteFriday As Date
    DteFriday = IIf(Weekday(Date) = 1, Date - 6, _
    Date - (Weekday(Date) - 6))
    Selection.InsertBefore (DteFriday)
    End Sub

  3. #3
    Registered User
    Join Date
    08-09-2012
    Location
    Norfolk,va
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Need help with date macro

    I hope that helps someone who know more about this then me. I would like the format of the date to read 29 April 2013 - 3 May 2013.

  4. #4
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Need help with date macro

    Try something based on:
    Please Login or Register  to view this content.
    Note: The above implementation requires a bookmark named "ThisWeek", so that the date goes there, rather than just wherever the cursor happens to be. You can run the macro any day of the week and it will output the corresponding Mon-Fri date range. The output week changes each Saturday. As coded, the macro outputs the weekday as well (for test/validation purposes), but you can omit that by deleting the two 'DDD, ' strings from the code.
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  5. #5
    Registered User
    Join Date
    08-09-2012
    Location
    Norfolk,va
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Need help with date macro

    If i add a second bookmark and name it "ThisWeek2" so it will add the same date on the second page how would i add it into the macro?

  6. #6
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Need help with date macro

    No, the macro is only coded to work with a single bookmark. In any event, if all you're doing is replicating the output, you should consider:
    a) formatting the output range with a unique Style name using a STYLEREF field in the page header/footer to replicate the data; and/or
    b) inserting a simple cross-reference to the "ThisWeek" bookmark, perhaps supplemented with a '.Fields.Update' line in the code, after '.Bookmarks.Add BmkNm, BmkRng'.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1