VBA Msgbox Custom Button Text

One functionality missing from the VBA MsgBox function is the ability to customize the button text. Using the MessageBox API, I wrote my own class to customize the button text, re-purposing some of the existing messagebox types to return which button was clicked (first, second, third). Custom Msgbox Buttons

Note: Updated 5-25-2016 to support 64-bit versions of Office.Note: Updated 12-29-2016 to to have close button enabled by default.Note: Updated 5-22-2017 to use Win API to get handle to application object window.Note: Updated 6-8-2017 fixed bug – Thanks to Greg Donnells and Brian High for pointing this out.

From MessageBox function API:
If a message box has a Cancel button, the function returns the IDCANCEL value if either the ESC key is pressed or the Cancel button is selected.
If the message box has no Cancel button, pressing ESC has no effect.

The only way the close button will be enabled is if the messagebox has only one button, or has a cancel button.
I had to make changes to the underlying buttons :

3 Buttons = YesNoCancel,
2 Buttons = OkCancel
1 Button = OK

So the only caveat is closing the dialog via escape will return the associated cancel button (button 3, button 2, button 1 respectively).

From MessageBox function API:
If a message box has a Cancel button, the function returns the IDCANCEL value if either the ESC key is pressed or the Cancel button is selected.
If the message box has no Cancel button, pressing ESC has no effect.

The only way the close button will be enabled is if the messagebox has only one button, or has a cancel button.
I had to make changes to the underlying buttons :

3 Buttons = YesNoCancel,
2 Buttons = OkCancel
1 Button = OK

So the only caveat is closing the dialog via escape will return the associated cancel button (button 3, button 2, button 1 respectively).

The modal issue may take some more time to fix.
In the meantime, you can just disable, then re-enable the parent form :

Instead of checking buttons for cancel caption, I added a UseCancel property to the clsMsgbox class.

I did this for simplicity since the cancel button has to be the second button with two buttons (vbOKCancel), and has to be the third button with 3 buttons (vbYesNoCancel).
Also, the caption could contain ampersands for shortcuts.
Lastly the caption could be a different language than english.