• How to insert yesterday’s date?

    Author
    Topic
    #353143

    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.

    Public Sub cmd_TypeDateConst()
        Selection.InsertDateTime DateTimeFormat:="dddd, MMMM dd, yyyy", InsertAsField:=False
    End Sub
    
    Viewing 1 reply thread
    Author
    Replies
    • #515793

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

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

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

      Dim dtToday As String
          dtToday = Format(Date - 1, "d MMMM yyyy")
          Selection.TypeText Text:=dtToday
      
    • #515832

      … and Legare …

      Thanks for this. Works perfectly!!

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

    Viewing 1 reply thread
    Reply To: How to insert yesterday’s date?

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: