Oxygeniusz
New Member
- Joined
- Jan 23, 2023
- Messages
- 1
- Office Version
- 365
- Platform
- 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