Excel ワークブックの VBA プロジェクトをパスワードで保護する
Contents
[
Hide
]
考えられる使用シナリオ
Aspose.Cells を使用して、ワークブックの VBA (Visual Basic for Applications) プロジェクトをパスワードで保護できます。[VbaProject.protect()](https://reference.aspose.com/cells/java/com.aspose.cells/vbaproject#protect(boolean,%20java.lang.String)) 方法。
サンプルコード
次のサンプル コードは、サンプル Excel ファイル、その VBA プロジェクトにアクセスし、パスワードで保護します。最後に、それを出力エクセルファイル.
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"); |