Add signature to Email body (1 Viewer)

JPR

Registered User.
Local time
Today, 05:24
Joined
Jan 23, 2009
Messages
192
Hello,
I am using the code below (it's only a part of the whole code) to open Outlook from a form. Is there a way I can also add the Signature already available in Outlook, in the body of the mail? Thank you for your help.

" ' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")

' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

With objOutlookMsg
' Set the Subject, Body, and Importance of the message.
.Subject = "test"
.Body = strBody"
 

theDBguy

I’m here to help
Staff member
Local time
Today, 05:24
Joined
Oct 29, 2018
Messages
21,357
Hi. This is an old topic. I can't remember when, but in some cases, the signature should be automatically added when you create an email. Other times, you'll have to read the HTML signature file from your computer and paste it into the end of the body of your email.
 
Last edited:

Minty

AWF VIP
Local time
Today, 12:24
Joined
Jul 26, 2013
Messages
10,354
If you open a blank email then save that (it will contain the signature only) then add it back to your real email, something like;

Code:
    Dim signature as String

    Set OutApp = CreateObject("Outlook.Application")
    OutApp.Session.Logon
    Set OutMail = OutApp.CreateItem(0)
    On Error Resume Next
    With OutMail
        .BodyFormat = olFormatHTML
        .Display
    End With
    
    signature = OutMail.HTMLBody
    
'''' Then Create your real email   

  With OutMail
    
        .To = Variable_To
        .CC = ""
        .BCC = ""
        .Subject = Variable_Subject
        '.MailItem.ReplyRecipients.Add = "flibble@somehwhere.com"
        '.SentOnBehalfOfName = "flibble@somehwhere.com"
        '.Attachments.Add (Variable_AttachmentFile)
        .HTMLBody = Variable_Body & signature
        .Display   'or use .Send
        .ReadReceiptRequested = False
    End With

You'll need to have all your objects Dimmed - it's just a snippet of the full code.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 20:24
Joined
May 7, 2009
Messages
19,169
firstly your signature (if you created one in Outlook) will be saved in folder:

C:\Users\yourNamel\AppData\Roaming\Microsoft\Signatures

now, go to the folder and look for a file with .htm extension.
jot down the filename.htm.

now on a module copy/paste this:
Code:
    Private Function ReadSignature(sigName As String) As String
       Dim oFSO, oTextStream
       Dim appDataDir, sig, sigPath, fileName As String
       appDataDir = Environ("APPDATA") & "\Microsoft\Signatures"
       sigPath = appDataDir & "\" & sigName

       Set oFSO = CreateObject("Scripting.FileSystemObject")
       Set oTextStream = oFSO.OpenTextFile(sigPath)
       sig = oTextStream.ReadAll
       ' fix relative references to images, etc. in sig
       ' by making them absolute paths, OL will find the image
       fileName = Replace$(sigName, ".htm", "") & "_files/"
       sig = Replace$(sig, fileName, appDataDir & "\" & fileName)
       ReadSignature = sig
       Set oTextStream = Nothing
       Set oFSO = Nothing
    End Function

on your outlook vba:

Code:
Dim Sig As String
Sig = ReadSignature("theSignatureFile.htm") 'do not include the path
Set objOutlook = CreateObject("Outlook.Application")

' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)


    With objOutlookMsg
        .To = "someone@gmail.com"
        .CC = "anotherPerson@gmail.com"
        .Subject = "the subject"
        '.body = MessageBody
        .HTMLBody = "your body here" & "<p><BR/><BR/></p>" & Sig
        .Display
    End With
 
Last edited:

bastanu

AWF VIP
Local time
Today, 05:24
Joined
Apr 13, 2010
Messages
1,401
I think all you needed to do was to use the HTMLBody instead of Body and the signature would be automatically inserted:
.HTMLBody = strBody
Cheers,
 

conception_native_0123

Well-known member
Local time
Today, 07:24
Joined
Mar 13, 2021
Messages
1,826

theDBguy

I’m here to help
Staff member
Local time
Today, 05:24
Joined
Oct 29, 2018
Messages
21,357

conception_native_0123

Well-known member
Local time
Today, 07:24
Joined
Mar 13, 2021
Messages
1,826
You may be talking about in Outlook. We're talking about in Access.
yes, but if you code or automate a message creation from access and open outlook objects or anything else in terms of instances, the sig should auto populate at the bottom as well. at least that's what I remember. the sig feature is *part* of the outlook program, and if an object that's created *inside* outlook uses that feature, it should show up. doesn't matter how it is created because the program is opened either way you do it. no? am I wrong?
 

bastanu

AWF VIP
Local time
Today, 05:24
Joined
Apr 13, 2010
Messages
1,401
You are right but you must use the right property of the mailitem object which is HTMLBody not Body like the OP has in the initial post (which forces the message to use plain text)

Cheers,
 

conception_native_0123

Well-known member
Local time
Today, 07:24
Joined
Mar 13, 2021
Messages
1,826
You are right but you must use the right property of the mailitem object which is HTMLBody not Body like the OP has in the initial post (which forces the message to use plain text)

Cheers,
bastanu, are you talking to me? just want clarification.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 05:24
Joined
Oct 29, 2018
Messages
21,357
yes, but if you code or automate a message creation from access and open outlook objects or anything else in terms of instances, the sig should auto populate at the bottom as well. at least that's what I remember. the sig feature is *part* of the outlook program, and if an object that's created *inside* outlook uses that feature, it should show up. doesn't matter how it is created because the program is opened either way you do it. no? am I wrong?
Unfortunately, that's not always the case. That why I said earlier that it sometimes does that and other times it doesn't. I just couldn't remember when it will do one or the other. For example, I think if you generate an email from Access and display the draft email before sending it, I think it will have the signature. However, I think if you simply send an email from Access without reviewing it first, I think it might not have the signature automatically attached. I think... :)
 

conception_native_0123

Well-known member
Local time
Today, 07:24
Joined
Mar 13, 2021
Messages
1,826
I think if you generate an email from Access and display the draft email before sending it, I think it will have the signature. However, I think if you simply send an email from Access without reviewing it first, I think it might not have the signature automatically attached. I think... :)
if what you're "thinking" is correct then dbGuy, obviously the issue is with the transacting of the draft window opening. there could not be any other answer to it. there is nothing else involved between the 2 scenarios you describe other than the transaction of the window initialization.

i will have to run a test myself. thanks.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 20:24
Joined
May 7, 2009
Messages
19,169
here is a sure way to display the Signature to your Outlook email.
make sure that you created your Signature first in Outlook:

File->Option->Mail->Signature (in Outlook 2019).
 

Attachments

  • outLookTest.accdb
    512 KB · Views: 569

Gasman

Enthusiastic Amateur
Local time
Today, 12:24
Joined
Sep 21, 2011
Messages
14,038
Unfortunately, that's not always the case. That why I said earlier that it sometimes does that and other times it doesn't. I just couldn't remember when it will do one or the other. For example, I think if you generate an email from Access and display the draft email before sending it, I think it will have the signature. However, I think if you simply send an email from Access without reviewing it first, I think it might not have the signature automatically attached. I think... :)
@theDBguy,

That is what I have noticed.
When I was doing it, I would split the body where the signature was and then append it at the end. That did not include any grahics however.

Then I saw that if you use .Display from seeing that mentioned in forums it would be shown.
 

JPR

Registered User.
Local time
Today, 05:24
Joined
Jan 23, 2009
Messages
192
Thanks to all of your for all the help. I really like arnelgp's sample db. I think it's great and for sure will borrow the idea.

Thank you
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 20:24
Joined
May 7, 2009
Messages
19,169
here is a modified version.
since you can have multiple "signatures" saved,
i added a combo so you can select which signature to use.
 

Attachments

  • outLookTestSignature.accdb
    576 KB · Views: 699

Nous1970

New member
Local time
Today, 13:24
Joined
Feb 18, 2018
Messages
21
I know this is an old threat, however I can't seem to get it to work.
In the preview I do get to see the image (So it seems to work so far), however it does not show up in outlook :-(
 

theDBguy

I’m here to help
Staff member
Local time
Today, 05:24
Joined
Oct 29, 2018
Messages
21,357
I know this is an old threat, however I can't seem to get it to work.
In the preview I do get to see the image (So it seems to work so far), however it does not show up in outlook :-(
What image? Is that your signature?
 

Users who are viewing this thread

Top Bottom