Proteggi con password il progetto VBA del workbook di Excel

Proteggere con password il progetto VBA del workbook Excel in C#

È possibile proteggere con password il progetto VBA (Visual Basic for Applications) del workbook con Aspose.Cells utilizzando il metodo VbaProject.Protect().

Codice di Esempio

Il seguente codice di esempio carica il file Excel di esempio, accede al suo progetto VBA e lo protegge con una password. Infine lo salva come file Excel di output.

// 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");