Microsoft Word

W

WadeB

At work I have password protected documents (I know the password). Each Day
Mon-Friday I need to add a date for the next day - except Friday when I need
to insert Mondays date. Is there a way to automate this so all I have to do
is click print when the document is opened? Not sure if this matters but, I
have about 70 different documents that I have to open and do this to everyday.

Thanks Wade
 
D

Dave Lett

Hi Wade,

Yes, you can automate this. Here's some sample code to get you started:

Dim dDate As Date
Dim oRng As Range
Select Case Weekday(Date)
Case vbMonday, vbTuesday, vbWednesday, vbThursday
dDate = Date + 1
Case vbFriday
dDate = Date + 3
Case Else '''Sat. or Sun.
''' do nothing
End Select

Set oRng = ActiveDocument.Range
oRng.Collapse Direction:=wdCollapseEnd
oRng.InsertAfter Text:=vbCrLf & dDate

You have a lot of options for formatting your date. The last line above is
only one example. Here's another, very easy alternative:

oRng.InsertAfter Text:=vbCrLf & FormatDateTime(dDate, vbLongDate)


HTH,
Dave
 

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