Schützen Sie das VBA Projekt der Excel Arbeitsmappe mit einem Passwort
Contents
[
Hide
]
Schützen Sie das VBA-Projekt der Excel-Arbeitsmappe in C# mit einem Passwort
Sie können das VBA (Visual Basic for Applications)-Projekt der Arbeitsmappe mit Aspose.Cells über die Methode VbaProject.Protect() passwortgeschützt machen.
Beispielcode
Der folgende Beispielscode lädt die Beispiel-Excel-Datei, greift auf ihr VBA-Projekt zu und schützt es mit einem Passwort. Schließlich speichert es die Datei als die Ausgabe-Excel-Datei.
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-.NET | |
//The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
//Load your source Excel file. | |
Workbook wb = new Workbook(dataDir + "samplePasswordProtectVBAProject.xlsm"); | |
//Access the VBA project of the workbook. | |
Aspose.Cells.Vba.VbaProject vbaProject = wb.VbaProject; | |
//Lock the VBA project for viewing with password. | |
vbaProject.Protect(true, "11"); | |
//Save the output Excel file | |
wb.Save(dataDir + "outputPasswordProtectVBAProject.xlsm"); |