Results 1 to 4 of 4
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to insert yesterday's date?

    I use a tiddy little macro (pasted below) hooked onto a toolbar menu to insert the current date as a constant into a document.

    If I'm maintaining a diary on a project, it's neat-oh to drop in the date and then type issues arising out of this day.

    Of course, I'd rather browse Woody's Lounge, so the diary gets put off until Tomorrow. So Today it is Tomorrow, and I want to drop Yesterday's date in there.

    I would have used an equation with an =NOW() expression, but that function doesn't seem to be available.


    I'd appreciate any help in setting this up, and yes, I would very much like the date to be fomattable.


    <pre>Public Sub cmd_TypeDateConst()
    Selection.InsertDateTime DateTimeFormat:="dddd, MMMM dd, yyyy", InsertAsField:=False
    End Sub
    </pre>


  2. #2
    BAM
    Guest

    Re: How to insert yesterday's date?

    *** Geoff W. URL Markup added ***

    Hi Chris,

    When it comes to dates you are better off using one of the date functions using VBA. Since you already have a macro, take a look at this article from the MS Word MVP FAQ site:
    <A target="_blank" HREF=http://mvps.org/word/FAQs/MacrosVBA/DateOfPrevMonth.htm>http://mvps.org/word/FAQs/MacrosVBA/DateOfPrevMonth.htm</A>

    Note that the article demonstrates returning the date for the previous month. For the previous day just change the first argument (Interval) to "d".

    You can obtain all of the arguments for the interval in Word VBA Help by looking up the DateDiff function.
    ~~~~~~~~~~~~~
    Cheers!

  3. #3
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How to insert yesterday's date?

    Chris: I use code like the following to inser the date:

    <pre>Dim dtToday As String
    dtToday = Format(Date, "d MMMM yyyy")
    Selection.TypeText Text:=dtToday
    </pre>


    If you want to insert yesterdays date, then you could use:

    <pre>Dim dtToday As String
    dtToday = Format(Date - 1, "d MMMM yyyy")
    Selection.TypeText Text:=dtToday
    </pre>

    Legare Coleman

  4. #4
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How to insert yesterday's date?

    ... and Legare ...

    Thanks for this. Works perfectly!!

    With a subtle modification I can browse the lounge for TWO days before getting down to work.

Posting Permissions

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