Microsoft Office Tutorials and References
In Depth Information
Forcing the User to Enable Macros
Selection.Range.HighlightColorIndex = wdNoHighlight¶
Else¶
MsgBox "No text is selected."¶
End If¶
End Sub¶
To change the highlight color, delete the text = wdYellow; type the equals sign (=)
again, and a list of values should appear. Select one of the values and press Enter.
Forcing the User to Enable Macros
These procedures provide methods to prevent users from successfully working
with a document if macros are not enabled.
Wrd
Example file:
WordProtection.doc,
DocFromCode.doc,
WeeklyReport.xls
Scenario: When distributing macros that manage
templates or documents, it is important that the user have
macros enabled; otherwise the macros won't work. For
obvious reasons, it is not possible to create a macro that
changes macro security settings; if it were, macro security
would be useless. This section discusses a number of ways
to prevent the user from working with a project unless
macros are enabled. There are a couple of code examples
to demonstrate how the techniques are applied.
Generating the Document Using VBA
Certainly, the most effective way is to generate the entire document when it is
opened or created from a template. The 'Document_Open' and 'AutoOpen'
procedures fire when a document is opened. A 'Document_New' or 'AutoNew'
procedure fires when a new document is created from a template.
In the document body, place a message telling the user how to enable macro
security so that the document can be created. If macros can be run, a macro
removes the message text and replaces it with the document, as shown by the
following sample code.
Tip: To open one of the sample documents without the AutoOpen macros running, hold down
the Shift key while it is opening. Holding the Shift key down when opening a file prevents
macros from executing. If this step is forgotten (happens all the time), just close the
document without saving the changes and try again.
 
Search JabSto ::




Custom Search