Hello all.
I am new to this forum and this is my first post, hope i will not get disappointed
a quick solution cause, email id separator
Thanks in advance ...
I am having a macro which send emails to different users via outlook, its working fine.
an array is build, a loop runs which send different mails depending on the count.
All the contents like email id's, subject, attachment path are written in an excel workbook.
Email ID - TO , CC, BCC - are written in excel workbook
Problem ,
1) I need to CC the mails to multiple users, and the email address are written in cell "b4"\
when i am writing single emailid in this cell, it works.
but when i write muliple email id in cell b4,separated by " ;" or "," it shows runtime error
" Outlook does not recognise one or more names"
2) Also, it always ask for permission that a program is sendimg email on your behalf .... asking for allow / dont allow
i want to remove this manual intervention.
i am attaching the code along with this email.
Sub SendMessage()
Dim i As Integer
Dim intRowCount As Integer
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim SendEmailTo, SendEmailCc, SendEmailBcc, SendEmailSub, AttachmentDir, AttachmentFile, attachmentPath As String
intRowCount = 2
' MonthYear = Format(Sheets("Dashboard").Range("S1").Value, "MMM-YYYY")
SendEmailCc = "emailaddress1;emailaddress2;emailaddress3"
'<-- Enter the email address here.
AttachmentDir = Sheets("Sheet2").Range("B1").Value
For i = 1 To intRowCount
AttachmentFile = Sheets("Sheet2").Range("d4:d100").Cells(i).Value
SendEmailTo = Sheets("Sheet2").Range("a4:a100").Cells(i).Value
SendEmailCc = Sheets("Sheet2").Range("b4:b100").Cells(i).Value
SendEmailCc = "emailaddress1;emailaddress2"
SendEmailSub = Sheets("Sheet2").Range("c4:c100").Cells(i).Value
SendEmailBcc = Sheets("Sheet2").Range("e4:e100").Cells(i).Value
' SendEmailSub = "CentreCode " & Sheets("Sheet2").Range("E2").Value
attachmentPath = AttachmentDir & AttachmentFile
' 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(SendEmailTo)
objOutlookRecip.Type = olTo
' Add the CC recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add(SendEmailCc)
objOutlookRecip.Type = olCC
' Add the BCC recipient(s) to the message.
' Set objOutlookRecip = .Recipients.Add(SendEmailBcc)
' objOutlookRecip.Type = olBCC
' Set the Subject, Body, and Importance of the message.
.Subject = SendEmailSub
' .Body = "This is the body of the message." & vbCrLf & vbCrLf
.Importance = olImportanceHigh 'High importance
' Add attachments to the message.
If Not IsMissing(attachmentPath) Then
Set objOutlookAttach = .Attachments.Add(attachmentPath)
End If
' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next
' Should we display the message before sending?
If DisplayMsg Then
.Display
Else
.Save
.Send
End If
End With
Set objOutlook = Nothing
Next i
End Sub
Bookmarks