Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 07-07-2017, 04:15 AM
gmayor's Avatar
gmayor gmayor is offline Executing a Word macro only after a certain date & time Windows 10 Executing a Word macro only after a certain date & time Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,142
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
See attached example
Attached Files
File Type: dotm OutOfDate.dotm (24.7 KB, 10 views)
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
 



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
Executing a Word macro only after a certain date & time Date & time stamp problems in Word XP Scotfan Word 3 03-09-2016 09:45 AM
Executing a Word macro only after a certain date & time Shift Excel Cell after executing a macro for second time LearningMacro Excel Programming 2 01-08-2015 03:05 PM
Executing a Word macro only after a certain date & time Word form w/ autopopulated date/time Dendalee Word 1 10-24-2012 11:40 PM
Executing a Word macro only after a certain date & time need help with macro date and time for dispatch sheets Jamesb8488 Word 1 04-28-2011 02:54 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:55 PM.


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