#1
|
|||
|
|||
Executing a Word macro only after a certain date & time
I have the need to run a Word 2013 macro, but only after a certain date & time. I know you can do this in Excel but I cannot figure out if this can be done in Word. Any ideas? |
#2
|
||||
|
||||
It guess it depends what it is that the macro is supposed to do. You could check the date whenever Word is started and you can check the date when a document or global template is opened and perform some process.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
I guess I should have been more specific. I am in charge of company templates. An upcoming project is going to require updated templates but those templates cannot be put in place until after the project has officially started. I am going to be out of office at this time and unable to to upload the new files, therefore I want to develop and automatic file copy based on a chosen input date. Please keep in mind that I am a novice and only have a rudimentary understanding of VBA.
|
#4
|
||||
|
||||
The short answer is no. You cannot delete or rename an open file and the file would have to be open in order to run the macro. The best solution I can think of is to put the new templates somewhere the users can access them and add the following code to the ThisDocument module of each old template (change the due dates as appropriate) and save as macro enabled templates. Users will not then be able to open the template or create new documents from it from that date, but would see a message instead.
Code:
Option Explicit Private Sub Document_New() If Format(Date, "yyyymmdd") >= Format("07/07/2017", "yyyymmdd") Then MsgBox "The template has expired, please download the latest version from 'somewhere'" ActiveDocument.Close End If lbl_Exit: Exit Sub End Sub Private Sub Document_Open() If Format(Date, "yyyymmdd") >= Format("07/07/2017", "yyyymmdd") Then MsgBox "The template has expired, please download the latest version from 'somewhere'" ThisDocument.Close End If lbl_Exit: Exit Sub End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#5
|
|||
|
|||
Thanks. That should work.
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
OneNote on Android phone View Tags? Enter Date, Time, Date & Time | DrTwinkyEsq | OneNote | 0 | 03-27-2017 07:54 PM |
Date & time stamp problems in Word XP | Scotfan | Word | 3 | 03-09-2016 09:45 AM |
Shift Excel Cell after executing a macro for second time | LearningMacro | Excel Programming | 2 | 01-08-2015 03:05 PM |
Word form w/ autopopulated date/time | Dendalee | Word | 1 | 10-24-2012 11:40 PM |
need help with macro date and time for dispatch sheets | Jamesb8488 | Word | 1 | 04-28-2011 02:54 PM |