Share via


How to: Permit code to run behind documents with restricted permissions

Applies to: yesVisual Studio noVisual Studio for Mac

Note

This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

You can use the Information Rights Management (IRM) feature of Microsoft Office to restrict permissions to a document or workbook. By default, the code behind a restricted Microsoft Office Word document or Microsoft Office Excel workbook is not permitted to run. You can change the default so that your managed code extensions can access the object model, and your solution will work.

Applies to: The information in this topic applies to document-level projects for Excel and Word. For more information, see Features available by Office application and project type.

You must be the author of the document or workbook or have Full Control access to be able to change the permission settings.

To permit code to run behind documents with restricted permissions

  1. Open the document or workbook in Word or Excel.

  2. Click the File tab, point to Prepare, point to Restrict Permission, and then click Restricted Access.

    Note

    On first use, you are prompted to install the Windows Rights Management client. After you install the client, you might need to repeat the steps.

  3. In the Permission dialog box, select Restrict permission to this document, and then click More Options.

  4. Under Additional permissions for users, select Access content programmatically.

    Word or Excel will permit programmatic access to the object model.

See also