godzilla185
New Member
- Joined
- Sep 27, 2021
- Messages
- 18
- Office Version
- 365
- Platform
- Windows
Hi,
I have a very useful code I made for work, which does the following:
1. removes duplicate client names
2. inserts contact list
3. Vlookup today's client names against the contact list to make the next step for client emails dynamic.
4. Generates emails to each client and inserts their corresponding excel files.
I got everything to work except the email signature in #4 (removed from code to show what is working so far)
The code for the email part is below (removed private information which is not relevant):
Columns H, I, J, and K hold respectively the "To", "Subject", "Body" and excel files to attach parts of the email.
I have looked at rondebruin and on this forum to add the signature part of the code and cannot get it to work. Am wondering if anyone can help.
...
Sub Email_and_AttachFile()
Dim r As Long
Dim m As Long
Dim sMail As String
Dim sFile As String
Dim oApp As Object
Dim oMsg As Object
Dim wd As Date
wd = WorksheetFunction.WorkDay(Date, -1)
Set oApp = CreateObject(Class:="Outlook.Application")
m = Range("K" & Rows.Count).End(xlUp).Row
For r = 2 To m
sFile = Range("K" & r).Value
Set oMsg = oApp.CreateItem(0)
With oMsg
.To = Range("H" & r).Value
.Subject = Range("I" & r).Value
.Body = "Good morning," & vbNewLine & Format(wd, "dd mmm yyyy") _
& Range("J" & r).Value & vbNewLine & "Many thanks," & vbNewLine & Signature
.CC = "bob”"
.Attachments.Add sFile
.Display
End With
Next r
End Sub
I have a very useful code I made for work, which does the following:
1. removes duplicate client names
2. inserts contact list
3. Vlookup today's client names against the contact list to make the next step for client emails dynamic.
4. Generates emails to each client and inserts their corresponding excel files.
I got everything to work except the email signature in #4 (removed from code to show what is working so far)
The code for the email part is below (removed private information which is not relevant):
Columns H, I, J, and K hold respectively the "To", "Subject", "Body" and excel files to attach parts of the email.
I have looked at rondebruin and on this forum to add the signature part of the code and cannot get it to work. Am wondering if anyone can help.
...
Sub Email_and_AttachFile()
Dim r As Long
Dim m As Long
Dim sMail As String
Dim sFile As String
Dim oApp As Object
Dim oMsg As Object
Dim wd As Date
wd = WorksheetFunction.WorkDay(Date, -1)
Set oApp = CreateObject(Class:="Outlook.Application")
m = Range("K" & Rows.Count).End(xlUp).Row
For r = 2 To m
sFile = Range("K" & r).Value
Set oMsg = oApp.CreateItem(0)
With oMsg
.To = Range("H" & r).Value
.Subject = Range("I" & r).Value
.Body = "Good morning," & vbNewLine & Format(wd, "dd mmm yyyy") _
& Range("J" & r).Value & vbNewLine & "Many thanks," & vbNewLine & Signature
.CC = "bob”"
.Attachments.Add sFile
.Display
End With
Next r
End Sub