View Single Post
 
Old 04-06-2022, 01:46 AM
kiwimtnbkr kiwimtnbkr is offline Windows 10 Office 2019
Advanced Beginner
 
Join Date: Oct 2017
Posts: 69
kiwimtnbkr is on a distinguished road
Default Exit Module sub code when cancel is selected

I have the following command button code in a module. When the command button is pressed, it calls the Workbook_BeforeSave routine to name the workbook correct before attaching it in an email complete with signature block. No problems - runs sweetly.

Code:
Sub emailrequest()
    Call OrderRequest.Workbook_BeforeSave(True, False)
Dim OutApp As Object
Dim OutMail As Object
Dim signature As String
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    On Error Resume Next
    
    With OutMail
        .To = "xxx@xxx.xxx"
        .Subject = "Order Request"
        .Attachments.Add ActiveWorkbook.FullName
        .display
    End With
 
    signature = OutMail.body
    With OutMail
        .CC = ""
    End With
    On Error GoTo 0
    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub
When the save as dialog box appears, if I select Cancel, the box disappears but the sub continues to run and attaches the workbook to an email.
How do I stop the module code from continuing if I select Cancel?
Reply With Quote