Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 03-30-2015, 02:41 AM
gmayor's Avatar
gmayor gmayor is offline Disableling macros when i save Windows 7 64bit Disableling macros when i save Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,144
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

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
Reply With Quote
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Disableling macros when i save Macro to save as pdf with ability to choose save as folder 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
Disableling macros when i save When I try to save an existing word doc, save as pops up and will not save... 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

Other Forums: Access Forums

All times are GMT -7. The time now is 10:17 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