Hope someone can help. I use the below code to email through outlook using VBA.
Dim cl As Range
Dim App As Object
Dim Itm As Object
Dim EBody As String
Set App = CreateObject("Outlook.Application")
Set Itm = App.CreateItem(0)
'EBody = "test"
For Each cl In Sheets("Data").Columns("B").Cells.SpecialCells(xlCellTypeConstants)
If cl.Value Like "?*@?*.?*" And LCase(cl.Offset(0, 1).Value) = "yes" And LCase(cl.Offset(0, 2).Value) = "en" Then
Set Itm = App.CreateItem(0)
With Itm
.SentOnBehalfOfName = """test"" <[email protected]>"
.Subject = "Test account number " & cl.Offset(0, 3).Value
.To = cl.Value
'.CC = CCTo
.Body = cl.Offset(0, -1).Value & vbNewLine & vbNewLine & _
cl.Offset(0, 5).Value & " " & cl.Offset(0, 6).Value & vbNewLine & _
cl.Offset(0, 7).Value & " " & cl.Offset(0, 8).Value & vbNewLine & _
cl.Offset(0, 9).Value & vbNewLine & vbNewLine & _
Date & vbNewLine & vbNewLine & vbNewLine & vbNewLine & _
cl.Offset(0, -1).Value & vbNewLine & vbNewLine & _
"Test "
.Display 'Just display the e-mail
'.Send
End With
Set Itm = Nothing
End If
Next cl
Set App = Nothing
I want to add a signature with Ron de Bruins code below, but I cant seem to get it to work
Function GetBoiler(ByVal sFile As String) As String
'**** Kusleika
Dim fso As Object
Dim ts As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
GetBoiler = ts.readall
ts.Close
End Function
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Dim SigString As String
Dim Signature As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
'Change only Mysig.htm to the name of your signature
SigString = Environ("appdata") & _
"\Microsoft\Signatures\Mysig.htm"
If Dir(SigString) <> "" Then
Signature = GetBoiler(SigString)
Else
Signature = ""
End If
Can someone let me know where and how I need to place the above code in my code to get the signature to work?
Bookmarks