Macro - Subtract one day from current date

M

Matt

Hello,
I have been reading past posts from people who want to auto put a date in
their document that is not currentdate. I have read "WORD Date & Time
Manipulation: Tips & Techniques" document and I tried doing exactly what it
has and I am not getting any closer to my goal. So I think a macro could be
the best bet.

So what I want to do (and I am open to suggestions about how it should be
done), I want to insert a date in a field, text box or whatever works best,
and have the macro subtract one day from the current day(TODAY) so it will
show yesterday's date, in this format "d-MMMM". HELPPP!!!!
 
S

StevenM

Matt,

On the other hand, if all you need is yesterday's date:

'
' Inserts Yesterday's Date as text at the cursor
'
Sub InsertYesterdaysDate()
Dim iDay As Integer
Dim iMonth As Integer
Dim dtYesterday As Date
dtYesterday = DateAdd("d", -1, Now)
iDay = DatePart("d", dtYesterday)
iMonth = DatePart("m", dtYesterday)
Selection.Collapse wdCollapseStart
Selection.Text = CStr(iDay) & " " & MonthName(iMonth)
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top