PDA

View Full Version : Solved: How to create Yes or No Message Box?



genracela
07-22-2010, 10:44 PM
I created an Active X button code that when you click it it will automatically save the file then go to another cell.

Here's a code that I did:
Private Sub CommandButton4_Click()
MsgBox ("PLEASE WAIT WHILE YOUR REQUEST IS BEING SAVED")
ThisWorkbook.Save
Range("A2").Select
End Sub

But I'm trying to create a Yes or No option instead of this, that if you click the active x button a msgbox will promp you if you want to save your file or no. Unfortunately I'm not able to write a perfect code.

I just want a msgbox that will promp:

msgbox = Do you want to save your updates?
Yes or No

If yes
Thisworkbook.save
range("A2").Select

if no
range("A2").select
msgbox = Are You Sure? Your updates will be lost if you won't save this file?
Yes or No

If yes
Thisworkbook.save
range("A2").Select

if no
range("A2").select


Thanks!

genracela
07-22-2010, 11:30 PM
Hi! I got it...

Thanks!

Private Sub CommandButton4_Click()
If MsgBox("DO YOU WANT TO SAVE YOUR REQUEST?", vbYesNo) = vbYes Then
ThisWorkbook.Save
Range("A2").Select
Else
Range("A2").Select
End If
End Sub

YasserKhalil
07-23-2010, 02:00 AM
Try this

If MsgBox("DO YOU WANT TO SAVE YOUR REQUEST?", vbYesNo) = vbYes Then
GoTo 1
Else
If MsgBox("Are You Sure?Your updates will be lost if you won't save this file?", _
vbYesNo) = vbYes Then
GoTo 1
Else
GoTo 2
End If
End If
1 ThisWorkbook.Save
2 Range("A2").Select

Bob Phillips
07-23-2010, 02:49 AM
Yasser,

Sorry, but that is truly awful!

YasserKhalil
07-23-2010, 03:04 AM
Hi xld
I'm just a beginner.. I'm not professional as you - certainly

Provide us with the best solution..We're waiting

Bob Phillips
07-23-2010, 03:22 AM
genracela already did.

mdmackillop
07-24-2010, 07:48 AM
Note that you can change the messagebox icon by adding available options as

If MsgBox("DO YOU WANT TO SAVE YOUR REQUEST?", vbYesNo + vbCritical) = vbYes Then