20. October 2011 09:27

How to protect documents with a macro DocX

Filed Under(CRM 2011 | DocumentsCorePack 2011) By cternek

Protection for generated documents is a common query from our customers. With DocX and Macros it is very simple to achieve this. 


Open the template, add the following Macro to the template and save it with the file extension .Docm.


Sub DCPMacro()
	ActiveDocument.Protect Password:="password", NoReset:=True, Type:=wdAllowOnlyReading, _     
           UseIRM:=False, EnforceStylelock:=False   
End Sub


This Macro will ensure that the created document is protected with a password.

The DCPMacro will be called after generating the document.

Other macros you could use are:

Macro-Name when will it will be called from the code
this macro will be called before the activity is written to CRM
this macro will be called after the activity is successfully created


If you want the Document Information Panel to be visible, you could add the following Macro (which will be executed before the activity is created and saved):

Sub DocumentsCorePackMacroBeforeCreateActivity()
    With Application
        .DisplayDocumentInformationPanel = Not .DisplayDocumentInformationPanel
    End With
End Sub


Here is an example template for the entity account:

DocumentInformationPanel.docm (26.02 kb)


Tag Cloud

This will be shown to users with no Flash or Javascript.

Page List