godzilla185
New Member
- Joined
- Sep 27, 2021
- Messages
- 18
- Office Version
- 365
- Platform
- Windows
Hi everyone,
I have played around with Ron de Bruin's and other insert signature code I saw on this website but cannot make my code work.
I made a VBA macro that creates emails from a table list in excel as below, It adjusts subject line, date and everything works as I want, except I'm having trouble adjusting the code to include the signature... If anyone can help.
Sub emailgen1()
' creates emails with updated dates as per the name list. Creates 1 email per name in column H
Dim i As Integer, Mail_Object, Email_Subject, o As Variant, lr As Long, Signature As String
lr = Cells(Rows.Count, "H").End(xlUp).Row
Set Mail_Object = CreateObject("Outlook.Application")
Dim wd As Date
wd = WorksheetFunction.WorkDay(Date, -1)
For i = 2 To lr
With Mail_Object.CreateItem(o)
.Subject = Range("I" & i).Value & Format(Date, "dd mmm yyyy") & " text " & Format(wd, "dd mmm yyyy")
.To = Range("H" & i).Value
.body = "Good morning," & vbNewLine & vbNewLine & " & Format(wd, "dd mmm yyyy")" & Range("J" & i).Value & vbNewLine & Signature
.CC = "client"
.Display
End With
Next i
MsgBox "E-mail successfully created", 64
Application.DisplayAlerts = False
Set Mail_Object = Nothing
End Sub
I have played around with Ron de Bruin's and other insert signature code I saw on this website but cannot make my code work.
I made a VBA macro that creates emails from a table list in excel as below, It adjusts subject line, date and everything works as I want, except I'm having trouble adjusting the code to include the signature... If anyone can help.
Sub emailgen1()
' creates emails with updated dates as per the name list. Creates 1 email per name in column H
Dim i As Integer, Mail_Object, Email_Subject, o As Variant, lr As Long, Signature As String
lr = Cells(Rows.Count, "H").End(xlUp).Row
Set Mail_Object = CreateObject("Outlook.Application")
Dim wd As Date
wd = WorksheetFunction.WorkDay(Date, -1)
For i = 2 To lr
With Mail_Object.CreateItem(o)
.Subject = Range("I" & i).Value & Format(Date, "dd mmm yyyy") & " text " & Format(wd, "dd mmm yyyy")
.To = Range("H" & i).Value
.body = "Good morning," & vbNewLine & vbNewLine & " & Format(wd, "dd mmm yyyy")" & Range("J" & i).Value & vbNewLine & Signature
.CC = "client"
.Display
End With
Next i
MsgBox "E-mail successfully created", 64
Application.DisplayAlerts = False
Set Mail_Object = Nothing
End Sub