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?
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.
Eskimo's Code looks like the answer to me. If you want to set the soft color everytime you create a new document, you would want to put the code that sets the color in the first sub "GlobalMacroStorage_DocumentNew". I would put the lines of code directly into that sub or you could make an entire private subroutine which does what you want, and store it in this module, then place a call to it in the GlobalMacroStorage_DocumentNew sub.
Thanks kindly; works great!
Glad to hear it!
That can also be a convenient place to set some piece of metadata that you always want in your document, e.g., specifying an author name that is different than what will otherwise automatically be inserted:
1
ActiveDocument.Metadata.Author = "Arvide Abernathy"
Neat! I've applied a few of the MetaData items just so I'll remember I can do that.