ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   vbyesno msgbox (https://www.excelbanter.com/excel-programming/416223-vbyesno-msgbox.html)

matt3542

vbyesno msgbox
 
Dear Forum members,

When opening a workbook I would like to use a vbYesNo MsgBox to prompt the
user to answer yes or no to a given question. Depending on whether they
answer yes/no I want another MsgBox to confirm their input. I have tried
using the following but to no avail, can anyone please help? Thanks, Matt

Private Sub Workbook_Open()
MsgBox ("Question")
If MsgBox = vbYes Then
MsgBox ("Reply if yes")
Else
MsgBox ("Reply if no")
End If

End Sub



Sam Wilson

vbyesno msgbox
 
dim x as variant
x = msgbox("Question")

if x = vbyesno...



"matt3542" wrote:

Dear Forum members,

When opening a workbook I would like to use a vbYesNo MsgBox to prompt the
user to answer yes or no to a given question. Depending on whether they
answer yes/no I want another MsgBox to confirm their input. I have tried
using the following but to no avail, can anyone please help? Thanks, Matt

Private Sub Workbook_Open()
MsgBox ("Question")
If MsgBox = vbYes Then
MsgBox ("Reply if yes")
Else
MsgBox ("Reply if no")
End If

End Sub



matt3542

vbyesno msgbox
 
Thanks Sam, much appreciated

"Sam Wilson" wrote:

dim x as variant
x = msgbox("Question")

if x = vbyesno...



"matt3542" wrote:

Dear Forum members,

When opening a workbook I would like to use a vbYesNo MsgBox to prompt the
user to answer yes or no to a given question. Depending on whether they
answer yes/no I want another MsgBox to confirm their input. I have tried
using the following but to no avail, can anyone please help? Thanks, Matt

Private Sub Workbook_Open()
MsgBox ("Question")
If MsgBox = vbYes Then
MsgBox ("Reply if yes")
Else
MsgBox ("Reply if no")
End If

End Sub



Dave Peterson

vbyesno msgbox
 
Option Explicit
Private Sub Workbook_Open()
dim Resp as long

resp = MsgBox(prompt:="Question", buttons:=vbyesno)
if resp = vbyes then
MsgBox "Reply if yes"
Else
MsgBox "Reply if no"
End If

End Sub

matt3542 wrote:

Dear Forum members,

When opening a workbook I would like to use a vbYesNo MsgBox to prompt the
user to answer yes or no to a given question. Depending on whether they
answer yes/no I want another MsgBox to confirm their input. I have tried
using the following but to no avail, can anyone please help? Thanks, Matt

Private Sub Workbook_Open()
MsgBox ("Question")
If MsgBox = vbYes Then
MsgBox ("Reply if yes")
Else
MsgBox ("Reply if no")
End If

End Sub


--

Dave Peterson

matt3542

vbyesno msgbox
 
Thanks again Dave, appreciated

"Dave Peterson" wrote:

Option Explicit
Private Sub Workbook_Open()
dim Resp as long

resp = MsgBox(prompt:="Question", buttons:=vbyesno)
if resp = vbyes then
MsgBox "Reply if yes"
Else
MsgBox "Reply if no"
End If

End Sub

matt3542 wrote:

Dear Forum members,

When opening a workbook I would like to use a vbYesNo MsgBox to prompt the
user to answer yes or no to a given question. Depending on whether they
answer yes/no I want another MsgBox to confirm their input. I have tried
using the following but to no avail, can anyone please help? Thanks, Matt

Private Sub Workbook_Open()
MsgBox ("Question")
If MsgBox = vbYes Then
MsgBox ("Reply if yes")
Else
MsgBox ("Reply if no")
End If

End Sub


--

Dave Peterson


Rick Rothstein \(MVP - VB\)[_2687_]

vbyesno msgbox
 
If you won't need the answer to the question any place else in your code,
you can process the MsgBox response directly in the If..Then statement and
eliminate a variable (that would normally be used to hold the answer)...

Private Sub Workbook_Open()
If MsgBox(prompt:="Question", Buttons:=vbYesNo) = vbYes Then
MsgBox "Yes button was pressed"
Else
MsgBox "No button was pressed"
End If
End Sub

Rick


"matt3542" wrote in message
...
Dear Forum members,

When opening a workbook I would like to use a vbYesNo MsgBox to prompt the
user to answer yes or no to a given question. Depending on whether they
answer yes/no I want another MsgBox to confirm their input. I have tried
using the following but to no avail, can anyone please help? Thanks, Matt

Private Sub Workbook_Open()
MsgBox ("Question")
If MsgBox = vbYes Then
MsgBox ("Reply if yes")
Else
MsgBox ("Reply if no")
End If

End Sub




matt3542

vbyesno msgbox
 
Hi Rick, Thankyou for taking the time to explain that, I did eventually try
that method and it worked.

Best regards
Matt

"Rick Rothstein (MVP - VB)" wrote:

If you won't need the answer to the question any place else in your code,
you can process the MsgBox response directly in the If..Then statement and
eliminate a variable (that would normally be used to hold the answer)...

Private Sub Workbook_Open()
If MsgBox(prompt:="Question", Buttons:=vbYesNo) = vbYes Then
MsgBox "Yes button was pressed"
Else
MsgBox "No button was pressed"
End If
End Sub

Rick


"matt3542" wrote in message
...
Dear Forum members,

When opening a workbook I would like to use a vbYesNo MsgBox to prompt the
user to answer yes or no to a given question. Depending on whether they
answer yes/no I want another MsgBox to confirm their input. I have tried
using the following but to no avail, can anyone please help? Thanks, Matt

Private Sub Workbook_Open()
MsgBox ("Question")
If MsgBox = vbYes Then
MsgBox ("Reply if yes")
Else
MsgBox ("Reply if no")
End If

End Sub






All times are GMT +1. The time now is 03:45 PM.

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