Check if Digital Signature of VBA Code is Valid

Check if Digital Signature of VBA Code is Valid in C#

The following code demonstrates the usage of this property using the sample excel file which you can download from the provided link. The same excel file has a valid signature but when we modify its VBA code and save the workbook and then recheck, we find its signature has become invalid.

// 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);
Workbook workbook = new Workbook(dataDir + "sampleVBAProjectSigned.xlsm");
// Signature is valid
Console.WriteLine("Is VBA Code Project Valid Signed: " + workbook.VbaProject.IsValidSigned);
// Modify the VBA Code, save the workbook then reload
// VBA Code Signature will now be invalid
string code = workbook.VbaProject.Modules[1].Codes;
code = code.Replace("Welcome to Aspose", "Welcome to Aspose.Cells");
workbook.VbaProject.Modules[1].Codes = code;
// Save
workbook.Save(dataDir + "output_out.xlsm");
// Reload
workbook = new Workbook(dataDir + "output_out.xlsm");
// Now the signature is invalid
Console.WriteLine("Is VBA Code Project Valid Signed: " + workbook.VbaProject.IsValidSigned);