Excel recalculation & OnSendMessage

Add-in Express™ Support Service
That's what is more important than anything else

Excel recalculation & OnSendMessage
Excel crash on automatic recalculation with OnSendMessage 
Michael Kaden


Guest


Dear Andrei,

I believe the following EXCEL inherent recalculation trigger will cause problems when applying the OnSendMessage method.

Deleting or inserting a row or column, which will force recalculation of all UDF's.

I have an AddIn with XXL UDF's which use the SendMessage method. The send Message will also send the range of the calling cell as a reference. The OnSendMessage Event will then change the colour of Cells around the calling cell. This works well except if any column or rows including empty ones are deleted by mouseclick.

The errors are as follows:

Err Number -2147467261
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Error Number 1004
Unable to get Interior property of Range class

Both errors are raised in the ComAddIn procedure which want to change the colour of the cell. The range of the column to be deleted is then highlighted(selected) and the mouse cannot access the sheet anymore.

I have the impression that on deleting the column the UDF's are triggered but send the caller range to the sendMessage before the columns are deleted. The OnSendMessage is then triggered after the columns are deleted and therefore the interior properties of the ()caller cell are not accessible any more. Of course I might be wrong there.

By the way this also happens if an empty column is deleted (for example Column Z) and all UDF's are in much lower columns (for example A-C).


What is the solution to this?

Thank you and kind regards.

Michael
Posted 04 Apr, 2018 08:51:03 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Hello Michael,

Did you ever describe what you need to achieve? If so, please point me to that description or re-send it to me.

Michael Kaden writes:
I have the impression that on deleting the column the UDF's are triggered


Add a debug message to the UDF to check whether it is called or not; use the DebugView utility to find this at the run time. Or, if you run Excel by pressing F5 in youor project, see the Immediate window.

Michael Kaden writes:
By the way this also happens if an empty column is deleted (for example Column Z) and all UDF's are in much lower columns (for example A-C).


Are your functions declared as IsVolatile=true?



Andrei Smolin
Add-in Express Team Leader
Posted 04 Apr, 2018 10:00:56 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Andrei Smolin writes:
Add a debug message to the UDF to check whether it is called or not; use the DebugView utility to find this at the run time. Or, if you run Excel by pressing F5 in youor project, see the Immediate window.


Michael,

I'm looking into the code you sent me for your other post. I suppose I won't be able to respond to it today, so I post this here.

Please note that using message boxes for debugging creates extra events in the host application and this may disguise the issue.

Also, your UDF functions shouldn't show message boxes: just imagine a user getting a zillion of them. You should log the exception and return an error value; see the AddinExpress.MSO.ADXExcelError enumeration.


Andrei Smolin
Add-in Express Team Leader
Posted 04 Apr, 2018 10:12:56 Top