Digitally Sign a VBA Code Project with Certificate produces exception in .NET

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:

        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);
// Save the workbook

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.


Thanks for your posting and using Aspose.Cells.

We were able to observe this issue and logged it in our database for a fix.

This issue has been logged as

  • CELLSNET-45266 - VbaProject.Sign Exception


Thanks for using Aspose.Cells.

Please download and try the latest fix and let us know your feedback.

The issues you have found earlier (filed as CELLSNET-45266) have been fixed in Aspose.Cells for .NET 17.4.0.

This message was posted using Notification2Forum from Downloads module by Aspose Notifier.