vba yes no boxes

bruise_pristene

New Member
Joined
Aug 27, 2003
Messages
31
Hi i have just managed to use vba for the first time to create a "yes/no" user input box. However, i am stuck next. How can i get excel to do something depending on whether the user clicks yes or no?



any help appreciated, thx


Steve
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
You need to name the box - assuming you're referring to a message box

Code:
Sub YADDA()

MSG1 = MsgBox("Yadda Yadda Yadda",vbyesno,"Yadda?")

If MSG1 = vbyes then
  MsgBox "Hello"
Else
  MsgBox "Naff Off"
End If

End Sub
 
Upvote 0
thanks a lot, my message is off the form "do you agree yadda yadda...", is there a way to adapt that code so that if the user clicks no it displays a message (something like "you cannot access this workbook") and then close the file?



ta
 
Upvote 0
Code:
Sub YADDA() 

MSG1 = MsgBox("Yadda Yadda Yadda",vbyesno,"Yadda?") 

If MSG1 = vbyes then 
  MsgBox "Hello" 
Else 
  MsgBox "This Workbook Will Now Close" 
  ActiveWorkbook.Close SaveChanges = True 'doesn't save
End If 

End Sub
 
Upvote 0
lasw10 said:
Code:
Sub YADDA() 

MSG1 = MsgBox("Yadda Yadda Yadda",vbyesno,"Yadda?") 

If MSG1 = vbyes then 
  MsgBox "Hello" 
Else 
  MsgBox "This Workbook Will Now Close" 
  ActiveWorkbook.Close SaveChanges = True 'doesn't save
End If 

End Sub
Small typo error :wink: - the SaveChanges argument needs to have a colon befor the equals sign (and True does save)
Code:
ActiveWorkbook.Close SaveChanges:=True   'does save
 
Upvote 0

Forum statistics

Threads
1,214,621
Messages
6,120,563
Members
448,972
Latest member
Shantanu2024

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