Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
In our daily work, there may be some important information in the Excel file; in order to protect the internal data from spreading, the company will not allow us to print them. This document will tell you how to prevent others from printing Excel files.
You can apply the following VBA code to protect your specific file from being printed.



The following sample code illustrates how to prevent users from printing an Excel file:
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "Sample.xlsx");
// Loads the workbook which contains hidden external links
const wb = new AsposeCells.Workbook(filePath);
const modules = wb.getVbaProject().getModules();
modules.get("ThisWorkbook").setCodes("Private Sub Workbook_BeforePrint(Cancel As Boolean)\r\n Cancel = True\r\n MsgBox \"Refusing to print in paperless office\"\r\nEnd Sub\r\n");
wb.save("out.xlsm");
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.