excel 如果msgbox响应为是,则运行Sub,如果否,则退出

jyztefdp  于 2022-12-30  发布在  其他
关注(0)|答案(1)|浏览(144)

打开工作簿时会出现一个消息框。它以询问是否需要帮助的问题结束。
如果答案是“否”,我想退出Sub并允许正常使用。
如果答案是“是”,我希望它运行另一个宏给我发电子邮件。
电子邮件和消息框可以工作,只是不是对答案的React部分。

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
rdlzhqv9

rdlzhqv91#

只处理Yes部分,忽略其余部分。
这就是你想要的吗?

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

相关问题