msgbox vbyesno

  • Thread starter Thread starter gatarossi
  • Start date Start date
G

gatarossi

dear all,

I'm trying to create a code to appear a msgbox type vbyesno, but I
don't now how create it. And I need help with the code, if the user
click in yes or in no.

for example, if the user click in yes, the workbook save and close; if
the user click in no the worbook only close.

thanks

andré.
 
Modify this to do exactly what you want, it is what I THINK you need.
Sub main()
iselection = MsgBox("choose", vbYesNo)

If iselection = 6 Then
Me.SaveAs "Filename"
ActiveWorkbook.Close (True)

End If

If iselection = 7 Then
Application.DisplayAlerts = False
ActiveWorkbook.Close (True)
End If

End Sub
 
andré,

Dim Response As Integer
Response = MsgBox("Do you want to save the workbook.", vbYesNo)
Select Case Response
Case Is = vbYes
ActiveWorkbook.Close SaveChanges:=True
Case Is = vbNo
ActiveWorkbook.Close SaveChanges:=False
End Select

An alternative:

If MsgBox("Do you want to save?", vbYesNo) = vbYes Then
ActiveWorkbook.Close SaveChanges:=True
Else
ActiveWorkbook.Close SaveChanges:=False
End If

To give the user the option to cancel closing:

Dim Response As Integer
Response = MsgBox("Do you want to save the workbook.", vbYesNoCancel)
Select Case Response
Case Is = vbYes
ActiveWorkbook.Close SaveChanges:=True
Case Is = vbNo
ActiveWorkbook.Close SaveChanges:=False
End Select
--
Earl Kiosterud
www.smokeylake.com


Note: Top-posting has been the norm here.
Some folks prefer bottom-posting.
But if you bottom-post to a reply that's
already top-posted, the thread gets messy.
When in Rome...

-----------------------------------------------------------------------
dear all,

I'm trying to create a code to appear a msgbox type vbyesno, but I
don't now how create it. And I need help with the code, if the user
click in yes or in no.

for example, if the user click in yes, the workbook save and close; if
the user click in no the worbook only close.

thanks

..
 
Back
Top