auto run macro when creating New file

I have a macro that sets the page background to a soft color.   To my knowledge their is no way to set that as a document default.
I'm pretty sure I saw code somewhere that indicated it was possible to run a macro anytime  file was created or opened.  Can anyone point me to sample code for that purpose?

Parents
  • You can do that in the "ThisMacroStorage" part of a VBA project with code such as this:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    Private Sub GlobalMacroStorage_DocumentNew(ByVal Doc As Document, ByVal FromTemplate As Boolean, ByVal Template As String, ByVal IncludeGraphics As Boolean)
    
        ActiveDocument.MasterPage.Layers("Desktop").Editable = False
    End Sub
    
    Private Sub GlobalMacroStorage_DocumentOpen(ByVal Doc As Document, ByVal FileName As String)
    
        ActiveDocument.MasterPage.Layers("Desktop").Editable = False
    End Sub
    

    .

    In those examples, I have the code right there, because it's only one line to lock the Desktop layer - but one can also call a public sub that exists elsewhere in that VBA project.

Reply Children