I have exposed some functions from my C# VSTO ribbon and I can call them with a VBA Excel button. One of these functions is an asynchronous function - its operations are placed on a separate thread so it does not lock Excel. I would like that when I click it, the button is disabled (cannot be clicked again) until the async function is completed. Is this possible with VBA, if so, how?
Here is an implementation of my code so far:
Sub myButton_Click()
' disable this button'
Dim addIn As AddIn
Dim automationObject As Object
Set addIn = Application.AddIns("myAddIn")
Set automationObject = addIn.Object
automationObject.myAsyncFunc
' enable this button when myAsyncFunc finishes execution'
End Sub
AsyncFuncCompletedevent on the C# side, and handling in on the VBA side using aPrivate WithEvents automation As TheEventSourceClassandPrivate Sub TheEventSourceClass_AsyncFuncCompleted()- if needed you could even pass data through the parameters.Set automation = addIn.AutomationAPIPrivate Sub automation_AsyncFuncCompleted(), mistyped that, too late to edit