Custom Signature Not Displayed When Account Selected

Outlook version
Outlook 2016 32 bit
Email Account
IMAP
Hi!

I am using a procedure to choose the correct account for sending a new e-mail that I adapted from this forum. The correct account is based on the Outlook folder I am in. Thanx! I can successfully choose the correct account, but the signature for the correct account does not show. Outlook always uses the default signature, no matter what account I choose. How can I correct this?

Thanx!

hb
 
Outlook version
Outlook 2016 32 bit
Email Account
IMAP
So...

I am trying to choose a sendmail account and then use the correct signature for that account. Here's what I have so far:

---------------------------------------------------------
Private Sub m_Inspector_Activate()

If TypeName(m_Inspector.CurrentItem) = "MailItem" And m_Inspector.CurrentItem.Sent = False Then

Dim objMail As Outlook.MailItem
Dim OutApp As Outlook.Application
Dim strBuffer As String
Dim objSignatureFile As Object
Set OutApp = Application
Set objMail = m_Inspector.CurrentItem
Set objFSO = CreateObject("Scripting.FileSystemObject")
enviro = CStr(Environ("appdata"))

If objMail.Sent = False Then
MsgBox "Setting SendAccount Next " + OutApp.Session.accounts.Item(2)
objMail.SendUsingAccount = OutApp.Session.accounts.Item(2)

' Set Signature File Name
strSigFilePath = enviro & "\Microsoft\Signatures\"
Set objSignatureFile = objFSO.OpenTextFile(strSigFilePath & "gcu.htm")
strBuffer = objSignatureFile.ReadAll
objSignatureFile.Close

' Need code here to replace default signature with the specific one I have indicated.

End If

End If

Set m_Inspector = Nothing

End Sub
----------------------------------------------------
This is just a test at this point. I have not yet included the logic to choose the sendmail account. I am just trying to get the basics to work! :)

I think I have everything correct so far. What I don't know how to do is to replace the default signature with the one I want.

All help appreciated!

Thanx. :)

hb
 
Outlook version
Outlook 2016 32 bit
Email Account
IMAP
Hi all -

I finally figured out the code to do what I need. This checks to see if the folder is called "GCU" or if it is a subfolder of "GCU." If so, it chooses a specific account to send the e-mail and uses a GCU signature instead of the default:

Code:
Private Sub m_Inspector_Activate()

' First, check to see if the current item is an email and that it has not been sent.
If TypeName(m_Inspector.CurrentItem) = "MailItem" _
And m_Inspector.CurrentItem.Sent = False Then

Dim MyCurrentFolder As Outlook.MAPIFolder
Dim MyCurrentFolderParent As Outlook.MAPIFolder
Dim objMail As Outlook.MailItem
Dim OutApp As Outlook.Application
Dim strBuffer As String
Dim objSignatureFile As Object

Set MyCurrentFolder = Application.ActiveExplorer.currentFolder
Set MyCurrentFolderParent = Application.ActiveExplorer.currentFolder.Parent
'Debug.Print MyCurrentFolder + "  " + MyCurrentFolderParent
Set OutApp = Application
Set objMail = m_Inspector.CurrentItem
Set objFSO = CreateObject("Scripting.FileSystemObject")

enviro = CStr(Environ("appdata"))

' Only runs if in folder GCU or a subfolder ("1-Pending Reviews" and "My Learners"
' are GCU subfolders that also have subfolders.
If MyCurrentFolder = "GCU" Or MyCurrentFolderParent = "GCU" Or MyCurrentFolderParent = _
"1-Pending Reviews" Or MyCurrentFolderParent = "My Learners" Then

If objMail.Sent = False Then
    objMail.SendUsingAccount = OutApp.Session.accounts.Item(2)
    strSigFilePath = enviro & "\Microsoft\Signatures\"
    Set objSignatureFile = objFSO.OpenTextFile(strSigFilePath & "gcu.htm")
    strBuffer = objSignatureFile.ReadAll
    objSignatureFile.Close
   
    ' Writes the signature to the email mesage
    With objMail
        .HTMLBody = strBuffer
        .Display
    End With
   
    End If

End If

End If

Set m_Inspector = Nothing

End Sub
----------------

I have two questions:

1. Every time this bombed during development, I had to shut down and restart Outlook to get it to trigger when an email is opened. Why? Is there some way I could have avoided that?
2. Why does this need to go in ThisOulookSession rather than a code Module?

hb

PS: Thanx to Diane P. for the help!!
 
Outlook version
Outlook 2016 32 bit
Email Account
IMAP
All -

I have encountered a problem. The code throws an error 438 (Object does not support property or method) when I open a calendar item. The offending code is:
Code:
If TypeName(m_Inspector.CurrentItem) = "MailItem" And m_Inspector.CurrentItem.Sent = False Then
I thought this checked to see if the item triggering the procedure was a "MailItem." No?
Thanx!
hb
 
Outlook version
Outlook 2016 32 bit
Email Account
IMAP
Fixed it:
Code:
' First, check to see if the current item is an email and that it has not been sent.

If TypeName(m_Inspector.CurrentItem) = "AppointmentItem" = False Then

If TypeName(m_Inspector.CurrentItem) = "MailItem" _
And m_Inspector.CurrentItem.Sent = False Then
The new line after the comment makes sure it is not a calendar item.

hb
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Is it still erroring? (I didn't get a chance to test it over the weekend).
 
Outlook version
Outlook 2016 32 bit
Email Account
IMAP
Thanx, no! Seems to be working. However, it works too well. :( I want to add the signature to the bottom of an e-mail, not replace the body of the e-mail with the signature. Right now, if I REPLY to an e-mail, the original e-mail is "replaced" by the signature. I'm sure this is because of the code:
Code:
 With objMail
        .HTMLBody = strBuffer
        .Display
    End With
Is there an option to HTMLBody that will just add the signature to the bottom of the REPLY?

Thanx!

hb
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
It should be
Code:
With objMail
        .HTMLBody = .HTMLBody & strBuffer
        .Display
    End With
 
Outlook version
Outlook 2016 32 bit
Email Account
IMAP
Hi -

I figured it out. I still have some problems getting the right signature to go "when" I want it, though. The code works fine for new e-mails, but the default signature is added to replies. I will need to write code that detects a reply. I think I can figure it out.

I did have two questions you might be able to help me with, though.

1. Every time this bombed during development, I had to shut down and restart Outlook to get it to trigger when an email is opened. Why? Is there some way I could have avoided that?
2. Why does this need to go in ThisOulookSession rather than a code Module?

Thanx!

hb
 

Top