Macro / VBA to run at document startup
Help!
Ok, so i'm working on a large project and am trying to figure out if what I want to do is even possible...
First step: Is it possible to run a macro in Word that takes the current date, whatever it is when the document is opened, and add 7 days to that date? The date format would be mmmm d, yyyy. I have two points within my 23 page document where i need this to happen and it works when I run the macro but it always adds the date to wherever my cursor is as well, I need to turn that off as well. Now, i found out it's possible to run a macro that prompts the user to click "ok" or whatever i want at the opening of the document but I can't figure out how to tie that to the document to run the macro that I found. Here are the macro's that I'm currently using:
To open a message:
Private Sub Document_Open()
'run.macro
MsgBox "Run Macro?", vbOKOnly, "Message"
End Sub
To add the date:
Sub DATEPLUS7()
Selection.TypeText Text:=Format(Date + 7, "mmmm d, yyyy")
Dim myStoryRange As Range
For Each myStoryRange In ActiveDocument.StoryRanges
With myStoryRange.Find
.Text = "[DATEPLUS7]"
.Replacement.Text = Format(Date + 7, "mmmm d, yyyy")
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
Next myStoryRange
End Sub
|