ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   'Yes' 'No' button on autoopen macro (https://www.excelbanter.com/excel-programming/299104-yes-no-button-autoopen-macro.html)

larry

'Yes' 'No' button on autoopen macro
 
I have an autoopen MsgBox macro created. Instead of the "OK" button, I want the user to choose between "Yes" and "No" buttons. Yes=a pathway to a designated network drive and folder, No=remain on current worksheet. Q1. Syntax to instruct Excel to include Yes and No buttons in the MsgBox prompt. Q2. Syntax to instruct Excel what to do when either button is clicked. Thank you for any help you may offer. Your expertise is greatly appreciated


officeguy

'Yes' 'No' button on autoopen macro
 
rc = MsgBox ("Hello",vbYesNo

if the user selects Yes, rc =
if the user selcts No, rc = 7

steveB

'Yes' 'No' button on autoopen macro
 
Larry,

Try this code:

'''''''''''''''''''
Dim ans As String
'
ans = MsgBox("Do you want to stay in this workbook?", vbYesNo)
If ans = 6 Then
MsgBox ("You have chosen to stay in this workbook")
ElseIf ans = 7 Then
MsgBox ("You have chosen to do something else")
Else
MsgBox ("You didn't make a choice")
End If
''''''''''''''''''''''''''''

hth
--

steveB

(Remove 'NOSPAM' from email address if contacting me direct)


"Larry" wrote in message
...
I have an autoopen MsgBox macro created. Instead of the "OK" button, I

want the user to choose between "Yes" and "No" buttons. Yes=a pathway to a
designated network drive and folder, No=remain on current worksheet. Q1.
Syntax to instruct Excel to include Yes and No buttons in the MsgBox prompt.
Q2. Syntax to instruct Excel what to do when either button is clicked.
Thank you for any help you may offer. Your expertise is greatly
appreciated.





All times are GMT +1. The time now is 01:53 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com