Beneindias
Board Regular
- Joined
- Jun 21, 2022
- Messages
- 120
- Office Version
- 365
- Platform
- Windows
- MacOS
Hi guys,
I have an excel file with a table, where I have clients and providers emails in column C.
I have the subject in cell G4
And I have the body of the email in cell G5.
I have a code written, but, it's not working as expected.
I was trying to loop through column C and past the emails to BCC field, after all emails are added to BCC, should populate subject(G4) and body(G5), and use my signature that is stored in outlook app.
Problem is:
- This code is not puting emails in bcc or in any field.
- The body is being pasted to outlook 2x instead of only one
- It's not using my signature.
Can you look in this code and help me?
It's the first time that i'm tryin to send emails from excel, so, I don't undestand what's missing.
Now, another question:
It's better to put all emails in bcc and send one big group email, or send an email for each contact?
(Don't want to be flagged as spam, because this is to send an email to our clients and providers.)
Thank you all
I have an excel file with a table, where I have clients and providers emails in column C.
I have the subject in cell G4
And I have the body of the email in cell G5.
I have a code written, but, it's not working as expected.
I was trying to loop through column C and past the emails to BCC field, after all emails are added to BCC, should populate subject(G4) and body(G5), and use my signature that is stored in outlook app.
Problem is:
- This code is not puting emails in bcc or in any field.
- The body is being pasted to outlook 2x instead of only one
- It's not using my signature.
Can you look in this code and help me?
It's the first time that i'm tryin to send emails from excel, so, I don't undestand what's missing.
VBA Code:
Sub SendEmails()
'Declare variables
Dim OutlookApp As Outlook.Application
Dim OutlookMail As Outlook.MailItem
Dim rng As Range, cell As Range
Dim email As String
'Create an instance of Outlook
Set OutlookApp = CreateObject("Outlook.Application")
'Create a new email
Set OutlookMail = OutlookApp.CreateItem(olMailItem)
'Loop through each cell in column C
For Each cell In ActiveSheet.Range("C1:C" & ActiveSheet.Cells(Rows.Count, "C").End(xlUp).Row)
'Check if the cell contains an email address
If (InStr(1, email, "@") > 0) And _
(InStr(InStr(1, email, "@"), email, ".") > InStr(1, email, "@")) Then
'Populate the email properties
With OutlookMail
.Bcc = .Bcc & ";" & cell.Value
End With
End If
Next cell
'Populate the remaining email properties
With OutlookMail
.Subject = ActiveSheet.Range("G4").Value
.Body = ActiveSheet.Range("G5").Value
.HTMLBody = "<HTML>" & "<BODY>" & .Body & "<br>" & OutlookMail.HTMLBody & "</BODY>" & "</HTML>"
.Display
'.Send
End With
'Cleanup
Set OutlookMail = Nothing
Set OutlookApp = Nothing
End Sub
Now, another question:
It's better to put all emails in bcc and send one big group email, or send an email for each contact?
(Don't want to be flagged as spam, because this is to send an email to our clients and providers.)
Thank you all