![]() |
#2
|
||||
|
||||
![]()
You could test the macro against the name of the document (or save the document as DOCX format and it will not have a macro).
In the case of the former, let's assume a docvariable field that displays the docvariable "varDate", which to demonstrate has a value that is the current time. The following macro saved in the ThisDocument module will only run if the document containing the macro is called 'docname.docm' Code:
Option Explicit Private Sub Document_Open() Dim oFld As Field If ThisDocument.Name = "docname.docm" Then For Each oFld In ThisDocument.Fields If oFld.Type = wdFieldDocVariable Then If InStr(1, oFld.Code, "varDate") > 0 Then oFld.Locked = False ThisDocument.Variables("varDate").Value = Format(Time, "hh:mm:ss") oFld.Update oFld.Locked = True Exit For End If End If Next oFld 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 |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
rvessio | Word VBA | 4 | 07-25-2016 12:37 PM |
VBA to save a workbook without the macros | OTPM | Excel Programming | 1 | 01-15-2014 12:42 PM |
![]() |
samanthab | Word | 3 | 01-19-2013 06:27 AM |
Word ask to save template whenever i save a derived document | jorbjo | Word | 3 | 10-04-2012 10:52 AM |
PowerPoint Crashes every time I try to save/save as | Crimson_Ninja | PowerPoint | 0 | 05-04-2011 01:54 PM |