Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 09-18-2019, 12:25 PM
bluefate25 bluefate25 is offline Macro / VBA to run at document startup Windows 10 Macro / VBA to run at document startup Office 2010
Novice
Macro / VBA to run at document startup
 
Join Date: Sep 2019
Posts: 2
bluefate25 is on a distinguished road
Question 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
Reply With Quote
 

Tags
current date, macro, vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro / VBA to run at document startup start a macro with command Line startup switches Fesazu Word 3 02-08-2018 12:15 AM
Spell check macro within macro button field doesn't work in one document samuelle Word VBA 0 07-20-2016 02:27 AM
Macro / VBA to run at document startup StartUP location ptmuldoon Word 2 05-12-2015 12:19 PM
Save As Macro using first line of document as document name redzan Word VBA 1 01-31-2015 09:24 PM
Macro / VBA to run at document startup Merge doc on startup arkay Mail Merge 1 03-20-2012 11:50 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:29 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft