Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 04-06-2022, 01:46 AM
kiwimtnbkr kiwimtnbkr is offline Exit Module sub code when cancel is selected Windows 10 Exit Module sub code when cancel is selected Office 2019
Advanced Beginner
Exit Module sub code when cancel is selected
 
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
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Standard Module, Class Module and UserForm jpl Word VBA 0 03-14-2022 07:20 AM
Exit Module sub code when cancel is selected VBA code not in module of new document produced by mail merge MP1989 Mail Merge 3 09-10-2018 02:16 PM
Exit Module sub code when cancel is selected pause VBA code to view PDF file then continue or cancel trevorc Excel Programming 3 06-17-2018 09:46 AM
Exit Module sub code when cancel is selected Inserting code line in Word Module mihnea96 Excel Programming 2 08-15-2017 04:57 AM
Exit Module sub code when cancel is selected Stop macro if no file is selected in dialog box (when user presses cancel instead of selecting file) spencerw.smith Word VBA 2 08-12-2014 07:56 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:20 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft