Sending emails with Access to multiple recipients

pnevilm

New member
Local time
Today, 01:18
Joined
Oct 9, 2010
Messages
4
I have some VBA code that works to send an email with several daily reports to one person, but I want to send these same reports to multiple recipients. I cannot reconcile the TO in VBA. Its probably something simple, but I am racking my brain testing this. Can anyone help?

Here's what I have so far:

Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("recipients name")
objOutlookRecip.Type = olTo
' Add the CC recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("copied name")
objOutlookRecip.Type = olCC
' Set the Subject, Body, and Importance of the message.
.Subject = "Subject"
.Body = "Body" & vbCrLf & vbCrLf
.Importance = olImportanceHigh 'High importance


' Add attachments to the message.
Set objOutlookAttach = .Attachments.Add("C:\path")

' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next
.Send
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub

My question is, how do I separate the recipients TO?
 
When you add multiple recipients, you use the .recipients.add multiple times i.e. once for each address that you are adding. Don't try to add multiple recipients in on go.


' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("recipient 1 name")
Set objOutlookRecip = .Recipients.Add("recipient 2 name")
objOutlookRecip.Type = olTo


hth
Chris
 
Sorry, you should define what each add is (more important for CC list):

' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("recipient 1 name")
objOutlookRecip.Type = olTo
Set objOutlookRecip = .Recipients.Add("recipient 2 name")
objOutlookRecip.Type = olTo

Actually, Add will add the recipient as a To type so it's not strictly necessary to define it but probably not a bad idea to do it anyway (for clarity).

hth
Chris
 

Users who are viewing this thread

Back
Top Bottom