Read Sheet for Outlook Email Creation: Error on Recipients.Add

pete234

Active Member
Joined
Feb 10, 2004
Messages
419
I am trying to get rid of some Outlook templates and want Excel to read my Sheet and create the email.
A compiler error generates on the Add Recipients line.
This worked with a meeting for some reason, it let me just refer to the cell.
But the olMailItem does not.
I don't want to hard code the Recipients in the macro (it says needs argument)
I want them to be read from one cell.
Any ideas appreciated.

Sub EmailTest()
If MsgBox("Create Test 'Yes' or 'No'", vbYesNo, "Test Email?") = vbNo Then Exit Sub
Worksheets("Outlook").Visible = True
Worksheets("Outlook").Activate
Dim olApp As Outlook.Application
Dim myItem As Outlook.MailItem
Dim r As Long
Set olApp = GetObject("", "Outlook.Application")
Set myItem = olApp.CreateItem(olMailtem)

' Start at row 2
r = 2

With myItem
.Subject = Cells(r, 1).Value
.Recipients.Add = Cells(r, 8).Value
.BodyFormat = olFormatHTML
.HTMLBody = Cells(r, 17).Value
.Importance = olImportanceHigh
.Display
End With
End Sub
 
Last edited:

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
I resolved this issue.
Needed to define Recipients as Dim.
Now it works.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,264
Messages
6,171,081
Members
452,377
Latest member
bradfordsam

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