![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Mar 2002
Location: rejdus@hotmail.com
Posts: 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 |
|
|
|
|
|
#2 |
|
Board Regular
Join Date: Feb 2002
Posts: 117
|
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 |
|
|
|
|
|
#3 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Portland, OR USA
Posts: 1,374
|
Quote:
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
[ This Message was edited by: Russell Hauf on 2002-04-10 14:29 ] |
|
|
|
|
|
|
#4 |
|
New Member
Join Date: Mar 2002
Location: rejdus@hotmail.com
Posts: 18
|
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. |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|