Hi there,
I’m seeing a null reference exception when trying to sign a vba project. I amended the code from your docs, to create a workbook from scratch rather than loading an existing one:
Code:
static public void TestSign(){ Workbook wb = <span style="color: #008800; font-weight: bold">new</span> Workbook(); VbaModule module; String vbaCode; <span style="color: #333399; font-weight: bold">int</span> index; vbaCode = <span style="background-color: #fff0f0">"Private Sub Worksheet_SelectionChange(ByVal Target As Range)\r\n"</span>; vbaCode += <span style="background-color: #fff0f0">" ActiveCell.Value = \"Hello\"\r\n"</span>; vbaCode += <span style="background-color: #fff0f0">"End Sub\r\n"</span>; index = wb.VbaProject.Modules.Add(wb.Worksheets[<span style="color: #6600EE; font-weight: bold">0</span>]); module = wb.VbaProject.Modules[index]; module.Name = <span style="background-color: #fff0f0">"Sheet1"</span>; module.Codes = vbaCode;
#if true
// Sign
X509Certificate2 cert = new X509Certificate2(@“SampleCert.pfx”, “1234”);
DigitalSignature ds = new DigitalSignature(cert, “Signing Digital Signature using Aspose.Cells”, DateTime.Now);
wb.VbaProject.Sign(ds);
#endif
// Save the workbook
wb.Save(@“SampleSigned.xlsb”);
}
Note:
If I create a spreadsheet using Excel and add the above VBA code using the Visual Basic IDE, and then load and sign using Cells, it works (as in example). But.. creating the above spreadsheet with aspose cells, and saving it and then loading it again to sign also fails with an exception.