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.
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.
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.
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.
@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);
}
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.
@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.
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