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 important information in an Excel file; in order to protect internal data from being spread, the company may not allow it to be printed. This document explains 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:
VbaModuleCollection object from the VbaProject property of the workbook.VbaModule object using the name ThisWorkbook.codes property of the VbaModule.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\n" +
"End 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.