Pulling email address from specific field and adding it to the .To fiel

nanders8

New Member
Joined
Sep 19, 2014
Messages
27
I have a form that I am wanting to send via email. I have the code and it works if I input an email address manually, however, I want to automate the process. I want the macro to pull the recipient email address from the worksheet and apply it to the .To field. '

Here is the code that i am using.....

Code:
With OutlookMail    .To =[B]I would like this field to pull data from cell B18.[/B]
    .CC = ""
    .BCC = ""
    .Subject = "Time Additions and Corrections for " & Range("B18")
    .Body = "Please see the attached GSS 27."
    .Attachments.Add Application.ActiveWorkbook.FullName
    .Send
End With
Set OutlookMail = Nothing
Set OutlookApp = Nothing
MsgBox "Your email has been sent to " & Range("B19")

Any assistance would be good. I tried the following and none of these worked.

Code:
 .To =[B]Range("B18")[/B]
Code:
 .To =Cells(18, 2[B])[/B]

None of these worked either.
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
I have not worked much with sending emails via Excel, but I wonder if your issue is that you are trying to do it within the "With Outlook" block.
Try capturing the cell value in a variable BEFORE the "With Outlook" block, and then reference that variable, i.e.
Code:
Dim emlTo as String
emlTo = Sheets("Sheet1").Range("B18")
With Outlook
    .To = emlTo
 
Upvote 0

Forum statistics

Threads
1,214,870
Messages
6,122,019
Members
449,060
Latest member
LinusJE

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