Macro for Bulk Emails

Oxygeniusz

New Member
Joined
Jan 23, 2023
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hello, i have problem with macro designed to send bulk emails. I want it to change "email from" address along with adding my default signature. I can't make it work both at the same time. If i delete red piece of the code below "email from" address is ok but i don't have my signature. If i add red code for signature, "email from address" is set to my default instead of xyz@gmail.com as i want to.

VBA Code:
Sub CreateMultipleEmails()

Dim OutApp As Object
Dim OutMail As Object
Dim sign As String

Set OutApp = CreateObject("Outlook.Application")

For I = 2 To 3 'change 3 to the number of rows you want to loop through
Set OutMail = OutApp.CreateItem(0)
[COLOR=rgb(226, 80, 65)]OutMail.display
sign = OutMail.htmlbody[/COLOR]
With OutMail
.Sender = ActiveSheet.Range("E" & I).Value
.To = ActiveSheet.Range("A" & I).Value 'change A to the column containing the email addresses
.Subject = ActiveSheet.Range("B" & I).Value 'change B to the column containing the email subjects
.Body = "Email Body"
'.Attachments.Add ActiveSheet.Range("C" & I).Value 'change C to the column containing the file paths for attachments
.htmlbody = ActiveSheet.Range("D" & I).Value & "<br>" + sign 'change D to the column containing the email body
'.htmlbody = .htmlbody & "<br><br>Best regards, <br>Your Name <br>Your Email" 'Add your signature
[COLOR=rgb(44, 130, 201)].SentOnBehalfOfName = "xyz@gmail.com"[/COLOR]
.display ' Instead of .Send to open the message for editing
Dim xFilePath As Variant
xFile = Split(ActiveSheet.Range("C" & I).Value, ";") 'change C to the column containing the attachments files paths
For Each xFilePath In Split(ActiveSheet.Range("C" & I).Value, ";")
    .Attachments.Add xFilePath
Next
End With
Set OutMail = Nothing
Next I

Set OutApp = Nothing

End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Forum statistics

Threads
1,215,427
Messages
6,124,831
Members
449,190
Latest member
rscraig11

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