When loading a special xlsm file Aspose.Cells.dll runs into an error

Hello, I have a lot of Office Excel test files to query with Aspose.Cells, among other things, whether they contain a VbaProject. Interestingly, I have an xlsm file that only contains a Hello World message box, which already causes an error when loading. The xlsm test file can be opened normally in Excel and the VBA code with the small routine can also be opened. I cannot see what is causing the crash when trying to load it with Aspose.Cells. Attached is the test file. It would be desirable if such problems did not cause a crash, but instead feedback was given as to what prevented loading.
The error occurs with the programme line:
Workbook workbook = new Workbook(file)
So before I can use other Aspose.Cells functions to query things like has VbaProject.

best regards
Bernd
Test__oe__4.7z (10,4 KB)

I’m using Aspose.Cells .Net in a .Net 8 Desktop Framework application.

@BeniL,

Thanks for the template XLSM file.

After initial testing, I was able to reproduce the issue as you mentioned by using your template XLSM file. I found “System.NullReferenceException - Object reference not set to an instance of an object” when loading the XLSM file.

We require thorough evaluation of the issue. We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): CELLSNET-57197

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Hi, thank you very much for your fast answer.

@BeniL,

You are welcome. We will keep you posted with updates once available on it.

@BeniL,

We are pleased to inform you that your issue (Ticket ID: “CELLSNET-57197”) has been resolved. The fix/enhancement will be incorporated in the forthcoming release (Aspose.Cells v24.12), scheduled for the first half of December 2024. You will be notified once the new version is published.

Hello Amjad, I have also noticed that the detection of xlsb files, whether they contain a VBAProject, does not work correctly. For example, if you create a new xlsx file and then save it as an xlsb file, it does not contain a VBAProject. In the Aspose.Cells check whether a VBAProject is included, the answer is True, but this is not correct. It would be nice if this could be corrected in one of the next versions.

best regards
Bernd

@BeniL,

This might be expected behavior. For your information, calling HasMacro can detect the presence of macros which is enough. When not present, it will return false. Please note that when you use/call Workbook.VbaProject in code, a default macro will be created, so when you check HasMacro again, it will return true, which is expected. Therefore, if you want to determine whether a workbook has macros or not, just directly call HasMacro. There is no need to call Workbook.VbaProject first, as HasMacro will definitely return true after calling Workbook.VbaProject.

Hello Anjad, thank you very much for your fast answer.

the way how I check this seems to be the wrong way, or? Here is the part of how I check this at the moment. What would be the right way?

try
{
Workbook workbook = new Workbook(file);
Aspose.Cells.Vba.VbaProject vbaProj = workbook.VbaProject;
if (vbaProj != null && vbaProj.IsProtected)
{
xProtected = “is proteced_______”;
}
else
{
xProtected = “__________________”;
}
if (workbook.HasMacro)
{
xhasVBAProject = “has VBAProject”;

@BeniL
Please refer to the following example code to detect and create the default VBA project.

Workbook workbook = new Workbook(file);
if (workbook.HasMacro)
{
    Console.WriteLine("VBA project exists");
}

if (!workbook.HasMacro) 
{
    Console.WriteLine("VBA project does not exist");
    //create default VAB project
    Aspose.Cells.Vba.VbaProject vbaProj = workbook.VbaProject;
    //you will get true value, Because a default VBA project has already been created.
    Console.WriteLine(workbook.HasMacro);

}

Hope helps a bit.

Hello John, thank you very much for the sample. I have now used the query for workbook.HasMacro first, as in your example, so that the results for Excel files are now correct.

For information: The change was not necessary when checking Word documents. Enclosed is my code in which I check for HasMacros at the end. Word documents without VBA code also return false.

Aspose.Words.Vba.VbaProject vbaProj = doc.VbaProject;
if (vbaProj != null && vbaProj.IsProtected)
{
xProtected = “is proteced_______”;
}
else
{
xProtected = “__________________”;
}
if (doc.HasMacros)
{
xhasVBAProject = “has VBAProject”;
}
else
{ …

@BeniL
Thank you for your feedback. You are welcome. I’m glad you have known how to detect VBA projects for two products. Words and Cells are two different products, and there are some differences in the design of their APIs. If you have any questions, please feel free to contact us at any time.

2 posts were split to a new topic: Require temporary licenses for Aspose.Words for .NET and Aspose.Cells for .NET and encountered related issues

The issues you have found earlier (filed as CELLSNET-57197) have been fixed in this update. This message was posted using Bugs notification tool by johnson.shi

Hello John, thank you very much. I’ve tested the new version successfully with the file, which has the problem bevor.
best regards
Bernd

@BeniL

Thanks for your feedback.

Good to know that your issue is resolved by the new version/fix. Please feel free to write us back if you have further queries or comments.