Can't Add Sheets to XLBookMBS

I want to let users reorder and delete sheets in an XLBookMBS. I put the sheets into the RowTags of a ListBox where the user can manipulate them, then on Save I make a new XLBookMBS and try to add the stored sheets into it with AddSheet. On the first pass through the loop newbook is ok, but on the second pass it has the error “index is out of range”. Tried it with InsertSheet and got the same result.

newbook = new XLBookMBS(True)

Dim sheet As XLSheetMBS

for row As Integer = 0 to Listbox1.LastRowIndex
  sheet = Listbox1.RowTagAt(row) // Cast it
  call newbook.AddSheet(sheet.Name, sheet) // Second parameter is "InitSheet" for copying

Shouldn’t AddSheet perform an “append” operation, i.e. without regard to any index?

Can you please have the result of AddSheet go in a variable and check whether this is nil?

And where do you see the error message?

On the first pass, an XLSheetMBS is returned. On the second pass, Nil is returned.

In the debugger:

I am not sure what could cause this.
The XLBookMBS object for the existing sheet object is still in memory?

I tried an example here and it works.
So maybe you like to work on a sample project to show the problem?

Yes it’s in a window property.

OK, will do, thanks.

From @Christian_Schmitz via PM:

"LibXL currently doesn’t allow to copy sheet from one book to another.
So AddSheet Parameter must taken from same book.

And we have a CopySheet method, that may help."