Custom MSGBOX Macro needed.

Mayk

New Member
Joined
Mar 18, 2002
Messages
18
What would be a macro code if i want to create MsgBox
with options ="yes" "no" "cancel"
eg.
Are you sure you want to go out from the application and save it>
and then three choices to choose from
YES NO CANCEL

i seen that in my friend project and i fouund it better method than just the Exit button which would use macro like the one below:

Sub Exit_button()
'
' Exit_button Macro
' Takes you out of the application.
'

'
ActiveWorkbook.Save
ActiveWindow.Close
End Sub

thnx for help
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Sub CommandButton2_Click()
Dim Ans As String
Ans = MsgBox("Do you wish to terminate this program? (Program will be saved) If no, then program will exit without saving! However you will be prompted before closing to confirm 'NO' as your choice ", vbYesNoCancel)
Select Case Ans
Case vbYes
Me.Hide
Workbooks("YOUR NAME OF WORKBOOK").save
Application.Quit

Case vbNo
Me.Hide
Application.Quit

Case vbCancel
Me.Hide
End Select
Unload Me
End Sub

This code is written assuming a user hits a commandbutton to exit the program, then the promp reads as listed above.
Hope this helps- Todd
 
Upvote 0
On 2002-04-10 14:20, Mayk wrote:
What would be a macro code if i want to create MsgBox
with options ="yes" "no" "cancel"
eg.
Are you sure you want to go out from the application and save it>
and then three choices to choose from
YES NO CANCEL

i seen that in my friend project and i fouund it better method than just the Exit button which would use macro like the one below:

Sub Exit_button()
'
' Exit_button Macro
' Takes you out of the application.
'

'
ActiveWorkbook.Save
ActiveWindow.Close
End Sub

thnx for help

Something like this:

Code:
varResponse = MsgBox "Are you sure you want to go out from the application and save it?", vbYesNoCancel,"Confirm Close"

Select Case varResponse
Case No, Cancel
    Exit Sub
Case Yes   ' do nothing (go on to next steps, the Save and Close).
End Select

-hth, Russell
This message was edited by Russell Hauf on 2002-04-10 14:29
 
Upvote 0
todd
me.hide
and
unload me
causes problem
because visual basic dont read it and taking it as an error.
could u give me some kind of advice.
 
Upvote 0

Forum statistics

Threads
1,214,385
Messages
6,119,208
Members
448,874
Latest member
b1step2far

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