Home > Enterprise >  VBA MsgBox IF statements?
VBA MsgBox IF statements?

Time:10-13

I'm trying to set up an IF statement for a vba MsgBox with YES/NO responses. Is it possible? This is what I have:

Sub EmailAttachments()

Dim Msg001 As String
Dim Msg002 As String

Msg001 = "Continue creating your email"
Msg002 = "Save your attachments prior to creating an email"

MsgBox "Have you saved your attachments", vbYesNo, "ATTENTION!"

If vb = Yes Then
MsgBox Msg001, vbOKOnly, "CONTINUE"
Else
MsgBox Msg002, vbOKOnly, "EMAIL NOT CREATED"
End if

End Sub

CodePudding user response:

Please, use the next way:

Sub EmailAttachments()
 Dim Msg001 As String, Msg002 As String, answer As VbMsgBoxResult

 Msg001 = "Continue creating your email"
 Msg002 = "Save your attachments prior to creating an email"

 answer = MsgBox("Have you saved your attachments?", vbYesNo, "ATTENTION!")

 If answer = vbYes Then
        MsgBox Msg001, vbOKOnly, "CONTINUE"
 Else
        MsgBox Msg002, vbOKOnly, "EMAIL NOT CREATED"
 End If
End Sub
  • Related