Custom Signature Not Displayed When Account Selected

Status
Not open for further replies.
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
 
Status
Not open for further replies.
Thread starter Similar threads Forum Replies Date
D Custom Search Folders not refreshing/updating automatically Using Outlook 0
F Validation on custom task form after task acceptance Outlook VBA and Custom Forms 1
K UDF with formula not showing on Calendar custom view. Outlook VBA and Custom Forms 0
S Create a clickable custom column field Outlook VBA and Custom Forms 0
I Error saving screenshots in a custom form in outlook 2016, outlook 365 - ok in outlook 2013, outlook 2010 Outlook VBA and Custom Forms 5
M VbScript for Command Button on Contacts Custom Form Using Outlook 1
G Other users can't see P.2 with custom fields in Form Outlook VBA and Custom Forms 0
O Create a custom contact form - questions before messing things up... Outlook VBA and Custom Forms 4
S Reference Custom Fields with VBA Outlook VBA and Custom Forms 2
L Custom Form Tutoral? Outlook VBA and Custom Forms 6
D Lost Access to Custom Form Outlook VBA and Custom Forms 4
M vCard does not have user-defined fields from my custom contact form (365) Using Outlook 1
S Outlook Custom Form Scripting only working when clicking on "Run this form" Outlook VBA and Custom Forms 2
A Custom VBA to sort emails into folders Outlook VBA and Custom Forms 0
Victor_50 Outlook 2013 Custom Contact Form starts with "E-mail 2" Outlook VBA and Custom Forms 2
C Custom Form (seperate layout pages and message reading pane) Outlook VBA and Custom Forms 0
C Reading Pane for Custom Form Outlook VBA and Custom Forms 2
M Custom Calendar Print Suggestions? Using Outlook 0
K Custom Category Colors Using Outlook 2
N Custom Form Controls Not Visible To Recipient Outlook VBA and Custom Forms 3
E To convert imported data to custom fields in Task list Outlook VBA and Custom Forms 1
Randy Redekopp How To Merge Contact Info to Email Custom Form Template Using Outlook 2
D Problem with custom form including _DocSiteControl1 Outlook VBA and Custom Forms 0
C Custom Outlook Form - Populate Information from Radio Button / Check Box Using Outlook 0
E Custom formula for columns Using Outlook 3
W Message class changes of a custom form changes to the default form Using Outlook 2
A Possible to hide ribbon with custom appointment form? Outlook VBA and Custom Forms 3
S Custom Form, copy user field data to message body Outlook VBA and Custom Forms 12
Andrew Quirl Custom form to route requests based on input criteria Outlook VBA and Custom Forms 1
D Using a VBA Custom Form to Send Reoccurring Email Upon Task Completion Outlook VBA and Custom Forms 4
W Setting up a custom form Outlook VBA and Custom Forms 2
A Greyed out checkbox in custom form Outlook VBA and Custom Forms 4
Z Outlook Custom Form: Adding Dropdown(Project Code) at the end of subject Outlook VBA and Custom Forms 0
Z Adding dropdown list using custom form Outlook VBA and Custom Forms 7
G Entered data in custom field goes in card and does not stay in list view Outlook VBA and Custom Forms 1
witzker Correct Format of custom Yes/No Checkboxes Outlook VBA and Custom Forms 0
O Searching for Custom Flags Using Outlook 3
J autocomplete function in custom form Using Outlook 1
S Custom user fields in received messages Outlook VBA and Custom Forms 1
J Backup .OST - Custom Contact Forms, Defined Fields, Notes Using Outlook 1
D Custom form with html hyperlink Outlook VBA and Custom Forms 7
P Outlook custom fields "events" Using Outlook 0
D populating listbox on custom form from Access Outlook VBA and Custom Forms 7
D Custom Form Accept and Reject Command buttons Outlook VBA and Custom Forms 2
D create an html table in outlook custom form 2010 using vba in MsAccess Outlook VBA and Custom Forms 7
Potty Ash MS Outlook 2010 custom form - validation or formula to request user to check a checkbox Outlook VBA and Custom Forms 16
H Custom autoforwarding, sending mail through outlook office 365 Using Outlook 1
J Custom form code doesn't run Outlook VBA and Custom Forms 2
R Custom Contact Form how to update when loaded. Outlook VBA and Custom Forms 6
G Copy Contact field to Appointment Custom Form Field Outlook VBA and Custom Forms 2
Similar threads


















































Top