Using Scripts to Manage Word's Security Options

Sample VBScript scripts that demonstrate how you can both retrieve and configure the Microsoft Word 2003 Security options.

Mapping the Dialog Box to the Word Object Model

The options referenced in the following scripts correspond to the options found on the Security tab of the Options dialog box. To access these options in Microsoft Word 2003, click Tools, click Options, and then click the Security tab. A mapping between the options available in this dialog box and the Microsoft Word object model is shown below.

Security

The scripts shown on this page were tested using Microsoft Word 2003. At least some of the functionality is likely to work on any version of Microsoft Word that supports Visual Basic for Applications (VBA); however, the scripts have not been tested using any of these other versions.

Sample Code for Retrieving Values

Sample script that retrieves the configuration information found on the Security tab of the Options dialog box in Microsoft Word 2003.

On Error Resume Next

Set objWord = CreateObject("Word.Application")
Set objOptions = objWord.Options
Set objDoc = objWord.Documents.Add()

Wscript.Echo "Document has password: " & objDoc.HasPassword
Wscript.Echo "Read-only recommended: " & _
    objDoc.ReadOnlyRecommended
Wscript.Echo "Remove personal information from file properties on save: " & _
    objDoc.RemovePersonalInformation
Wscript.Echo "Store random numbers to improve merge accuracy: " & _
    objOptions.StoreRSIDOnSave
Wscript.Echo "Warn before printing, saving or sending a file that " & _
    " contains tracked changes or comments: " & _
        objOptions.WarnBeforeSavingPrintingSendingMarkup

objWord.Quit

Sample Code for Modifying Values

Sample script that sets the Remove personal information from file properties on save option in Microsoft Word to TRUE. Note that this option must be configured on a per-document basis. This sample script sets the option but does not save the document or quit Word.

On Error Resume Next

Set objWord = CreateObject("Word.Application")
objWord.Visible = TRUE
Set objOptions = objWord.Options
Set objDoc = objWord.Documents.Add()
objDoc.RemovePersonalInformation = TRUE

The sample scripts are not supported under any Microsoft standard support program or service. The sample scripts are provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.