View Single Post
 
Old 07-07-2017, 04:15 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,137
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