View Single Post
 
Old 01-24-2019, 11:47 AM
Charles Kenyon Charles Kenyon is offline Windows 10 Office 2016
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,468
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Here is a macro that, if placed in a macro enabled template, will create a new document based on the template and close the template if someone opens the template.


Code:
Sub AutoOpen()
      ' Prevent opening of template with macros active
      ' Creates a new document based on the template instead of opening the template
      ' 24 January 2019
      ' Charles Kenyon
      '
      If ActiveDocument.Name = ThisDocument.Name Then
          Documents.Add (ThisDocument.FullName)
          ThisDocument.Close SaveChanges:=False
      End If
  End Sub

I've attached such a template.
Note, to open such a template for editing, you must hold down the Shift key when opening it.

It would need to be stored in a trusted location such as the Workgroup Templates folder. If you place it somewhere not OK'd for macros, then it will open ordinarily and if macros are enabled, the macro would run.
Attached Files
File Type: zip Template That Can't Be Opened.zip (28.1 KB, 10 views)
Reply With Quote