VB Message Box

magician

New Member
Joined
Mar 21, 2007
Messages
9
Is it possible to stipulate your own buttons instead of the generic Yes, No, Cancel etc??

Thanks
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
If you want to customise completely then you will need to use a UserForm instead of a message box. However, there are a variety of different options available for buttons on a message box.
 
Upvote 0
Yes, you can. However, it is not for VBA newbies. One limitation is that you still have to use a pre-defined message box (yes/no/cancel or abort/retry/ignore) and the width of the buttons is fixed per the type of pre-defined msgbox you select; so you have to be pretty succinct to make whatever text you want to put on the button fit. Also you have to trap against the original return values.

Long story short? Do as Lewiy suggests and use a UserForm. In the end it's about the same amount of work and a UF is a whole lot more flexible.
 
Upvote 0
This is ithe Basic set of options:
Options are chained using a Plus [+], see sample below, to link the options wanted.


Sub myMsg()

myBody = "This is a Test!"
myTitle = "Test!"

myMsgTypeOptionAM = vbApplicationModal 'user must respond before continuing current application
myMsgTypeOptionSM = vbSystemModal 'all applications suspended until user responds

'Show one of these Icons in the MsgBox!
myMsgIconOptionC = vbCritical
myMsgIconOptionE = vbExclamation
myMsgIconOptionI = vbInformation
myMsgIconOptionQ = vbQuestion

'Make this One Button the Default in the MsgBox!
myMsgDefaultButt1 = vbDefaultButton1
myMsgDefaultButt2 = vbDefaultButton2
myMsgDefaultButt3 = vbDefaultButton3
myMsgDefaultButt4 = vbDefaultButton4

myMsgHlpButt = vbMsgBoxHelpButton 'Include the HELP button option!

'Display one of these Button sets!
'vbOK = 1, vbCancel = 2, vbAbort = 3, vbRetry = 4, vbIgnore = 5, vbYes = 6, vbNo =7

myMsgButtsOKC = vbOKCancel
myMsgButtsOK = vbOKOnly
myMsgButtsRC = vbRetryCancel
myMsgButtsYN = vbYesNo
myMsgButtsYNC = vbYesNoCancel

MsgBox myBody, _
myMsgIconOptionI + myMsgButtsOK, _
myTitle

End Sub
 
Upvote 0
Take a look at the Class code I posted in this post, it will inprove the Msgbox so it can be colored and do animation and other things the standard does not, yet it will work much like the standard in your code!


http://www.mrexcel.com/board2/viewtopic.php?t=279683



It is for the most part Rafaaj2000's class code addition he posted here:

http://www.mrexcel.com/board2/viewtopic.php?t=212296

It does not crash for me but he warns that it does on some systems?
That is why I added more instructions on how to load it than he did.
 
Upvote 0
:eek: Holy Cow! Dat's a summa fancy code dere, meester Joe! :eek:

Note to self: check out Joe's code first chance I get. :cool:

<sup>edit</sup> Ah! I didn't see the bottom part of your post -- Jaafar was involved too... No wonder it's so fancy! That dude is flat out scary sometimes... :biggrin: <sub>/edit</sub>
 
Upvote 0
Ya, I tried to get Jaafar in as a MVP and did, but he did not think he had the time, so he opted to remain a Board Regular rather than move up to MVP. He has not posted as much as he did. He mainly did VB to VBA stuff, all quite good. A real asset to code solutions.
 
Upvote 0
Yeah, one of the many impressive things I've seen him do is to take a shot on the age-old "highlight the cell under the mouse/cursor" idea. He did some stuff with trapping mouse moves over cells via API calls that was pretty impressive. Never did pan out completely -- the code was twitchy; and of course, it always had to be looping in the background to trap mouse movement. But he got as close as I ever saw anyone to pulling that one off. But I'm drifting us a bit off-topic and I try to limit that sort of thing to the lounge... :wink:
 
Upvote 0

Forum statistics

Threads
1,215,029
Messages
6,122,757
Members
449,094
Latest member
dsharae57

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top