Access creates emails in Outlook. Use default signature?

Hi!

I have some Access VBA code that creates an email with specific information in Outlook.

Is there a way to set it to create the email using my default signature from Outlook?

Here's my code:
Private Sub EmailProofButton_Click()
    Dim mess_body As String    'this will be the body text of the email.
    Dim appOutLook As Outlook.Application
    Dim MailOutLook As Outlook.MailItem
    Dim greeting As String      'this will be the beginning of the mess_body
    Set appOutLook = CreateObject("Outlook.Application")
    Set MailOutLook = appOutLook.CreateItem(olMailItem)
    If Hour(Time()) < 12 Then greeting = "Good morning!"
    If Hour(Time()) >= 12 Then greeting = "Good afternoon!"
    If Hour(Time()) >= 18 Then greeting = "Good evening!"
    
    'now we're going to build the body text of the email
    mess_body = greeting & " " & "Some text for the email." & _
    vbCrLf & vbCrLf & _
    "Some more text:" & vbCrLf & vbCrLf & _
   vbCrLf & vbCrLf & _
    "I look forward to your response." & vbCrLf & _
    vbCrLf & vbCrLf & _
    "Thank you." & vbCrLf & _
    "a signature that was typed into VBA, but I want it to use my default Outlook signature instead."
   
    Set appOutLook = CreateObject("Outlook.Application")
    Set MailOutLook = appOutLook.CreateItem(olMailItem)
    
    'Now we're going to set up the email
    With MailOutLook
        .To = "me@me.com"
        .Subject = "Subject"
        .Body = mess_body
        .Save
    
    End With

End Sub

Open in new window


Thanks for your help!
LVL 10
etech0Asked:
Who is Participating?
 
etech0Author Commented:
After extensive Googling, I've found a solution!!

I changed

.body = .body & mess_body

Open in new window

to
.htmlbody = .htmlbody & mess_body

Open in new window


and added
.display

Open in new window

before that line.

Just one issue, if you're still there...

After using .display to show the email (which, it seems, adds the signature), the email is opened. Is there a way to close it? I tried
.close

Open in new window

, but it gave an error.

Thanks!
0
 
pteranodon72Commented:
etech0,

The message starts with the default signature already in it. The problem is that you are overwriting the default signature by replacing the entire Body in line 29.

        .Body = mess_body & .Body 'existing .Body has default signature.

Hope this helps!
pT72
0
 
etech0Author Commented:
Thanks for your response!

However, that did not seem to help.

I tried testing it with Debug.Print .Body, but it just gave me an empty line.

Any other suggestions?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
etech0Author Commented:
Could the problem be that the email signature contains an image?
0
 
pteranodon72Commented:
Good call -- it is. It appears that if the default signature is text only, it is assigned to the MailItem's Body field at creation. If the default signature is HTML, like yours, it does not appear in the HTMLBody until you call MailItem.Display. After doing that, you can get the HTML that comprises the signature from the HTMLBody property. However, your goal of injecting other text into that HTML page is outside of my skill set!

Perhaps other experts can help out.

pT72
0
 
etech0Author Commented:
If I comment out the line that sets the .body, I get a blank email - not even my html signature.

Any ideas, folks?
0
 
etech0Author Commented:
Any ideas?
0
 
Jeffrey CoachmanMIS LiasonCommented:
wild guess....

.Signature="YourSignatureName"
Here you would use the name of your signature, that you used when you created your signature.
0
 
etech0Author Commented:
That was a nice try. However,
"Object doesn't support this property or method"

Any other ideas?
0
 
etech0Author Commented:
Anyone out there?
0
 
etech0Author Commented:
Looks like I found my own solution!

Thanks for your input, though!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.