How to Prevent Users from Printing Excel File with Golang via C++
Contents
[
Hide
]
Possible Usage Scenarios
In our daily work, there may be some important information in an Excel file; in order to protect internal data from being spread, the company may prohibit printing it. This document explains how to prevent others from printing Excel files.
How to Prevent Users from Printing File in MS-Excel
You can apply the following VBA code to protect your specific file from being printed.
- Open the workbook that you do not allow others to print.
- Select the Developer tab in the Excel ribbon and click on the View Code button in the Controls section. Alternatively, you can hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.

- Then, in the left Project Explorer, double‑click on ThisWorkbook to open the module and add some VBA code.

- Then save and close the code, return to the workbook, and when you attempt to print the sample file, printing will be blocked and you will see the following warning box:

How to Prevent Users from Printing Excel File using Aspose.Cells for C++
The following sample code illustrates how to prevent users from printing an Excel file:
- Load the sample file.
- Get the VbaModuleCollection object from the VbaProject property of the Workbook.
- Get the VbaModule object via the “ThisWorkbook” name.
- Set the Code property of the VbaModule.
- Save the sample file to xlsm format.