Password Protect the VBA Project of Excel Workbook
Contents
[
Hide
]
Possible Usage Scenarios
You can password protect the VBA (Visual Basic for Applications) Project of workbook with Aspose.Cells using VbaProject.protect() method.
Sample Code
The following sample code loads the sample Excel file, accesses its VBA Project, and protects it with a password. Finally, it saves it as an output Excel file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(PasswordProtecttheVBAProjectofExcelWorkbook.class) + "WorkbookVBAProject/"; | |
// Load your source Excel file. | |
Workbook wb = new Workbook(dataDir + "samplePasswordProtectVBAProject.xlsm"); | |
// Access the VBA project of the workbook. | |
VbaProject vbaProject = wb.getVbaProject(); | |
// Lock the VBA project for viewing with password. | |
vbaProject.protect(true, "11"); | |
// Save the output Excel file | |
wb.save(dataDir + "outputPasswordProtectVBAProject.xlsm"); |