Check if VBA Project is Protected and Locked for Viewing
Check if VBA Project is Protected and Locked for Viewing in C#
Aspose.Cells allows you to check if VBA (Visual Basic for Applications) Project of Excel file is protected and locked for viewing. For this, the API provides the VbaProject.IslockedForViewing property. If it is locked for viewing, then the VbaProject.IslockedForViewing property returns true.
Sample Code
The following sample code loads the sample Excel file and checks if VBA (Visual Basic for Applications) Project of Excel file is protected and locked for viewing. Please also see its Console Output for a reference.
// 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 + "sampleCheckifVBAProjectisProtected.xlsm"); | |
//Access the VBA project of the workbook. | |
Aspose.Cells.Vba.VbaProject vbaProject = wb.VbaProject; | |
//Whether "Lock project for viewing" is true or not. | |
Console.WriteLine("Is VBA Project Locked for Viewing: " + vbaProject.IslockedForViewing); |
Console Output
This is the console output of the above sample code when executed with the provided sample Excel file.
Is VBA Project Locked for Viewing: True