• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1670
  • Last Modified:

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!
0
etech0
Asked:
etech0
  • 8
  • 2
1 Solution
 
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
 
etech0Author Commented:
Could the problem be that the email signature contains an image?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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:
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
 
etech0Author Commented:
Looks like I found my own solution!

Thanks for your input, though!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 8
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now