Alter Email VBA

maxfli

New Member
Joined
Sep 14, 2010
Messages
26
I have a spreadsheet that works great to deliver worksheets as attachments via email. I have this in the Outlook section of the code:
VBA Code:
'Uncomment one or the other of the following 2 lines
            .Display    'to show and require manual send for each email
            '.Send       'to send each email immediately

I want to give the user the option to turn on what I will call Automatic Emails which will simply change the code to .Send as opposed to .Display
VBA Code:
'Uncomment one or the other of the following 2 lines
            '.Display    'to show and require manual send for each email
            .Send       'to send each email immediately

I have a Workbook_Open routine so my thoughts are I would prompt the user there on OPEN if they want to turn on Automatic Email.
Can someone suggest how to do make this work.

One other thing to mention is the code loops through all the tabs in the workbook and potentially sends 40 emails at once so I cannot prompt the user inside of the loop.

Thanks
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
In the module that contains your code to send the email, declare this at the top:
VBA Code:
Public SendEmail As Boolean
In the Sub to send the email:
VBA Code:
If SendEmail Then
   .Send
Else
   .Display
End If
In Worksheet_Open:
Rich (BB code):
Modulex.SendEmail = vbYes = MsgBox (prompt:="Do you want to send emails immediately? If you say No, the emails will be displayed and you will have to click Send to send them.", buttons:=vbYesNo)
where Modulex is the name of the module that has the code to send the mail.
 
Upvote 0
Solution

Forum statistics

Threads
1,214,920
Messages
6,122,262
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top