Matteo NNZ
Matteo NNZ

Reputation: 12685

Excel application crashing on ThisWorkbook.Save - where ThisWorkbook is an add-in

I have built an add-in that, apart for the code, is storing on its sheets some data that are functional to the add-in itself.

The user, through an user interface, can decide to remove some of the sheets from the add-in workbook, by selecting their names from a ListBox object appearing on the user form that shows up when called on the workbook currently in use. So the idea is:

For j = 0 To MyListBox.ListCount - 1
    If MyListBox.Selected(j) Then
        sheetsToDelete.Add ws(j) 'where ws(j) is the sheet with that name
    End If
Next j

The code above is not the real code, but just a sample to better express the concept. The real code works fine, I've tested in debug, but I just wanted to communicate the concept.

Once this is done, I would like to save the changes (i.e. the add-in after the sheets deletion) and so far I've done it with:

ThisWorkbook.Save

However, when this line of code is hit, "Excel application does not respond, the program will be terminated" (Excel workbook completely freezed):

enter image description here

I have checked in debug if the workbook is not corrupted, but it looks fine:

enter image description here

... it's my add-in...

enter image description here

... and it's containing the 2 sheets I expect it to contain:

enter image description here

Any tip on how to debug this? Unfortunately I cannot provide a full-reproduceable code snippet, I'm not being able..., but I might give more info if needed... anyone has encountered my some problem or can give me a nice tip?

Upvotes: 1

Views: 328

Answers (1)

Chrismas007
Chrismas007

Reputation: 6105

IsAddin Documentation

There was another case where this was an issue. Not sure how this affects the .Save:

ThisWorkbook.IsAddin = False
'Run Code Here
ThisWorkbook.IsAddin = True

Upvotes: 1

Related Questions