727
Views
6
Comments
[Advanced Excel] Problem adding new sheets to a Workbook 
Question
advanced-excel
Service icon
Forge asset by Carlos Freitas

Hello Outsystems team

I'm trying to add a new sheet to an Excel file. As you can see in the image below, I started by creating an Excel Workbook. Then, I use a For Each to iterate a binary data list (my point here is to create a new sheet according to each element of that list). After that I use a Workbook_Open action where the Binary_Data input is the current element of that list, and then I use the Workbook_AddSheet action, and that's where the problem begins. My arguments here are the WorkBook that I created in the first action, some random name from a list (then I remove that name from the list in order not to create 2 sheets with the same name) and for the WorkSheet input I used the output of the Workbook_Open action, which contains the Binary data from the list that I want to add. I already debugged, and there's a problem right here, an error saying "Object reference not set to an instance of an object". I have no idea why, since I'm using two Objects as inputs in this action.

Does anyone understands why is this happening?

Alexandre

OutsystemsCapture.PNG
UserImage.jpg
Alexandre Pereira

Here´s the image

2025-09-25 22-50-38
Hanno

Alexandre

Apologies for the delayed reply.

Attached is your .oml with slight modification. Note that you need to pass in the Worksheet object to the Workbook_Addsheet action, and not the excel file as a whole.

In the attached .oml I have built out the logic to correctly extract the worksheet that you want to add.

Please let me know if it solves your problem.

Hanno

ComparadorExcel.oml
UserImage.jpg
Alexandre Pereira

Hanno wrote:

Alexandre

Apologies for the delayed reply.

Attached is your .oml with slight modification. Note that you need to pass in the Worksheet object to the Workbook_Addsheet action, and not the excel file as a whole.

In the attached .oml I have built out the logic to correctly extract the worksheet that you want to add.

Please let me know if it solves your problem.

Hanno

Hi Hanno

I changed my code according to yours, but I still got the same error, "Object reference not set to an instance of an object", which makes no sense to me, since I'm clearly using an object type as input... do you have any idea why is this happening?


2025-09-25 22-50-38
Hanno

Well, usually you would get that error if the object is not of the correct type.

I'll try and do a few tests to see why that error is occurring.

Hanno

2022-03-01 15-42-44
Thiago Mari
Champion

Hanno wrote:

Well, usually you would get that error if the object is not of the correct type.

I'll try and do a few tests to see why that error is occurring.

Hanno

Hi, 


Here occur the same error and the Object is the output Select Worksheet.



Can help?


Cheers

2019-10-30 12-05-20
Eduardo Chaves

Hi,

I faced the same problem today. 

In my situation, i was sending to the action "workbook_addsheet", in the parameter "workbook" from the action "worksheet_select" return instead of using the "workbook_open" return parameter.




Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.