Toggle email send/display with variable

zJenkins

Board Regular
Joined
Jun 5, 2015
Messages
148
I have a macro that sends an email to a list of users. I want to be able to allow the user to select whether to display or send the email via a drop down list. On my worksheet I have a drop down list that has "display" and "send". I thought I could capture that selection using a variable (emailType) and add that to the With OutlookMail section of the code, but I think I'm missing something....

VBA Code:
Sub emailReports()

Dim OutlookApp As Object
Dim OutlookMail As Object
Dim finalRow As Integer
Dim reportDate As String
Dim fileLocation As String
Dim emailRecipient As String
Dim emailType As String

finalRow = Workbooks("HS_Critique_Master V2.xlsm").Worksheets("Sht_data").Cells(Rows.Count, 1).End(xlUp).Row
reportDate = Workbooks("HS_Critique_Master V2.xlsm").Worksheets("Sht_data").Range("E1").Value
emailType = Workbooks("HS_Critique_Master V2.xlsm").Worksheets("Sht_data").Range("emailSelect").Value

For i = 7 To finalRow

emailRecipient = Workbooks("HS_Critique_Master V2.xlsm").Worksheets("Sht_data").Range("F" & i).Value
fileLocation = Workbooks("HS_Critique_Master V2.xlsm").Worksheets("Sht_data").Range("G" & i).Value

Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookMail = OutlookApp.CreateItem(0)

On Error Resume Next

With OutlookMail
    .To = emailRecipient
    .CC = ""
    .BCC = ""
    .Subject = "HotShop Critique - " & reportDate
    .Body = "Hello, please review the attached Hotshop Critique file for " & reportDate
    .Attachments.Add (fileLocation)
    .emailType
End With
   
Set OutlookMail = Nothing
Set OutlookApp = Nothing

Next i
...
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Thinking about it, unless there is a simpler solution, I'll just use and if...then statement to solve it.
 
Upvote 0

Forum statistics

Threads
1,215,701
Messages
6,126,290
Members
449,308
Latest member
VerifiedBleachersAttendee

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