Reputation: 6262
The xlam Excel addin I'm building is interacting with externally sourced spreadsheet. The trouble is that the sheet, among other things in Workbook Change event has code that throws a MsgBox popup, messing with automation as it waits for user input. The popup is not called directly - the Workbook Change event is calling a custom Sub called "ShowPopup". Then inside the "ShowPopup" we have MsgBox call.
My thought was that if I could override the ShowPopup sub, I could prevent it from creating the MsgBox. Is it possible to do?
Constraints to the potential solutions:
Upvotes: 0
Views: 106
Reputation: 6262
I managed to solve my problem, although not in the way I originally planned. In the end it involves overriding the MsgBox Function.
For future reference here are the steps.
Global macroRunning As Boolean
macroRunning = True
and opposite after the loop.Create a new module, I called it MsgBoxHack
and put this code inside:
Public Function MsgBox( _
Prompt, _
Optional Buttons As VbMsgBoxStyle = vbOKOnly, _
Optional Title, _
Optional HelpFile, _
Optional Context _
) _
As VbMsgBoxResult
If IsMissing(Title) Then
Title = "Overriden MsgBox"
End If
If macroRunning = False Then
MsgBox = VBA.Interaction.MsgBox(Prompt, Buttons, Title, HelpFile, Context)
End If
End Function
macroRunning
is set to True
you won't see any MsgBoxesDownside - This overriden MsgBox function will run on all workbooks you work on while the addin is enabled in Excel.
Upvotes: 1