Home > Back-end >  Run Sub if msgbox response is Yes. Exit if No
Run Sub if msgbox response is Yes. Exit if No

Time:12-28

I have a message box that appears when the workbook is opened. It finishes with a question asking if help is needed.

If the answer is "No" I want to Exit Sub and allow normal usage.
If the answer is "Yes" I want it to run another macro to send me an email.

The email and message box subs work. Just not the portion of reaction to the answer.

Private Sub Workbook_Open()

Worksheets("Report").Columns("S:S").EntireColumn.Hidden = True
Worksheets("Report").Columns("T:T").EntireColumn.Hidden = True
Call Campbell_Initiative

End Sub


Sub SendHelp()
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
On Error Resume Next
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
xMailBody = "MY NAME," & vbNewLine & vbNewLine & _
            "I am having an issues with my report. Can you contact me when you have time?" & vbNewLine & vbNewLine & _
            "Respectfully,"
On Error Resume Next
With xOutMail
    .To = "MY EMAIL ADDRESS"
    .CC = ""
    .BCC = ""
    .Subject = "FSR WD REPORT HELP"
    .Body = xMailBody
    .Send
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub


Sub Campbell_Initiative()
' Campbell_Initiative Macro
 
Keyboard Shortcut: Ctrl e
 
Range("A2").Select
On Error Resume Next
ActiveSheet.ShowAllData
On Error Resume Next
ActiveSheet.Circlelnvalid

Call OpMsgB
End Sub

 
Sub OpMsgB()
MsgBox "If you are seeing item circled in RED, those cells do not match the standardized format or list choices." & vbNewLine & vbNewLine & "This is a new report, that was thrown built in a hurry. If you find anyting wrong or need something changed/add, Please contact MY NAME @ MY EMAIL " & vbNewLine & vbNewLine & " Do you need Help?", vbYesNo   vbQuestion, "REPORT HELP"
 
     'If answer = vbNo Then Exit Sub
Call SendHelp
End If
End Sub

CodePudding user response:

Just handle the Yes part and ignore the rest.

Is this what you are trying?

Sub OpMsgB()
    Dim msg As String
    
    msg = "If you are seeing item circled in RED, those cells do not match "
    msg = msg & "the standardized format or list choices."
    msg = msg & vbNewLine & vbNewLine
    msg = msg & "This is a new report, that was thrown built in a hurry."
    msg = msg & "If you find anyting wrong or need something changed/add, "
    msg = msg & "Please contact MY NAME @ MY EMAIL"
    msg = msg & vbNewLine & vbNewLine
    msg = msg & "Do you need Help?"
    
    If MsgBox(msg, vbYesNo   vbQuestion, "REPORT HELP") = vbYes Then Call SendHelp
End Sub
  • Related