Email Signature - how do i add it to this code? (1 Viewer)

Mark75

New member
Local time
Yesterday, 17:53
Joined
Jun 20, 2010
Messages
5
Hello,

I'm a bit of a novice programmer and really need some help with this.

I've got the code below to work fine but when it creates the new mail message it doesn't add the signature. I've been searching but with no luck. Any ideas how I add the default outlook signature to the email message?
Thanks for any help in advance.

Private Sub Command40_Click()

On Error GoTo TrapEmailError:
Dim rsEmail As DAO.Recordset
Dim olApp As Object
Dim objOutlook As Object
Dim ObjMessage As Object
Dim strbody As String
Dim strsubject As String
Dim sfilepath As String
Dim shtml As String
Dim db As DAO.Database
Dim stremail As String


Const olto As Long = 1
Const olMailItem As Long = 0

Set objOutlook = CreateObject("Outlook.Application")


Set db = CurrentDb
Set rsEmail = CurrentDb.OpenRecordset("tblEmailClients")


While Not rsEmail.EOF

stremail = rsEmail.Fields("Email").Value
strsubject = rsEmail.Fields("subject").Value

strbody = rsEmail.Fields("detail").Value


Set ObjMessage = objOutlook.CreateItem(olMailItem)



With ObjMessage

.To = stremail
.Subject = strsubject
.HTMLBODY = strbody
.Attachments.Add (Me.AttachmentPath)
.Display
'.Send

End With
rsEmail.MoveNext

Wend


MsgBox "All emails have been sent, check your sent items in outlook.", , "Email Confirmation"
Set rsEmail = Nothing
Set ObjMessage = Nothing


TrapEmailError:
0
'MsgBox Err.Description
End Sub
 

Mark75

New member
Local time
Yesterday, 17:53
Joined
Jun 20, 2010
Messages
5
Thanks for that but I didnt find what I was hoping for. Any other suggestions?
 

Christopherusly

Village Idiot.
Local time
Today, 01:53
Joined
Jan 16, 2005
Messages
81
This example add a signature to a mail with a small plain message.
Change the mail address and the name of the signature file in the code before you run it.

S
Code:
ub Mail_Outlook_With_Signature_Plain()
' Don't forget to copy the function GetBoiler in the module.
' Working in Office 2000-2010
    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)

    strbody = "Hi there" & vbNewLine & vbNewLine & _
              "This is line 1" & vbNewLine & _
              "This is line 2" & vbNewLine & _
              "This is line 3" & vbNewLine & _
              "This is line 4"

    'Use the second SigString if you use Vista as operating system

    SigString = "C:\Documents and Settings\" & Environ("username") & _
                "\Application Data\Microsoft\Signatures\Mysig.txt"

    'SigString = "C:\Users\" & Environ("username") & _
     "\AppData\Roaming\Microsoft\Signatures\Mysig.txt"

    If Dir(SigString) <> "" Then
        Signature = GetBoiler(SigString)
    Else
        Signature = ""
    End If

    On Error Resume Next
    With OutMail
        .To = "ron@debruin.nl"
        .CC = ""
        .BCC = ""
        .Subject = "This is the Subject line"
        .Body = strbody & vbNewLine & vbNewLine & Signature
        'You can add files also like this
        '.Attachments.Add ("C:\test.txt")
        .Send   'or use .Display
    End With
    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub
 

Mark75

New member
Local time
Yesterday, 17:53
Joined
Jun 20, 2010
Messages
5
Thanks for the quick response.

I saw something similar to that, the issue is there may be a few different users so I want to avoid hard keying their username etc..

SigString = "C:\Documents and Settings\" & Environ("username") & _
"\Application Data\Microsoft\Signatures\Mysig.txt"
 

Christopherusly

Village Idiot.
Local time
Today, 01:53
Joined
Jan 16, 2005
Messages
81
& Environ("username") should get the username from the computer they are on, meaning you do not have to hardcode usernames ... well this is my understanding at least.
 

Mark75

New member
Local time
Yesterday, 17:53
Joined
Jun 20, 2010
Messages
5
ah ok, thanks for all your help I'll have a crack at it tonight and post back how it goes..
 

Users who are viewing this thread

Top Bottom