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
 
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
 
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!!
 
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
 
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
 
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
 
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.
Similar threads
Thread starter Title Forum Replies Date
sjbtax Update Task Custom Field based upon Task Overdue Status Outlook VBA and Custom Forms 8
boblewis Technical Issue with Custom Form - Save to Drafts Not Syncing Outlook VBA and Custom Forms 1
G Apply Custom Contacts form to all existing Contacts Outlook VBA and Custom Forms 1
G Add Map It button to Custom Contacts Form in Outlook Outlook VBA and Custom Forms 1
G Outlook 2021 Add Picture to Custom Contact Form Outlook VBA and Custom Forms 2
X Custom icon (not from Office 365) for a macro in Outlook Outlook VBA and Custom Forms 1
P Can't add custom field to custom Outlook form, it always adds to the Folder instead Outlook VBA and Custom Forms 2
AndyZ Contact Custom Form Tiny Text Outlook VBA and Custom Forms 3
A How to reduce size of custom contact form? Outlook VBA and Custom Forms 3
S Custom Contact card - need help creating one Outlook VBA and Custom Forms 1
S Outlook 2019 Custom outlook Add-in using Visual Studio Outlook VBA and Custom Forms 0
S Adding Custom Forms Outlook VBA and Custom Forms 4
Witzker How to get the button Karte ( map) in custom contact form Outlook VBA and Custom Forms 2
B Outlook 2019 Custom Email form - Edit default email form Outlook VBA and Custom Forms 6
D Outlook 365 Custom forms field limit? Outlook VBA and Custom Forms 4
J PSA: How to create custom keyboard shortcut for "Paste Unformatted Text" in Outlook on Windows Outlook VBA and Custom Forms 1
M copy field value to custom field Outlook VBA and Custom Forms 0
J Does the .fdm contain my custom form? How to make ol use it? - ol2007 Outlook VBA and Custom Forms 4
J ol2021 custom form not displaying pics Outlook VBA and Custom Forms 37
N "Perform a Custom Action" Outlook VBA and Custom Forms 0
cbufacchi Outlook 365 Populate custom Outlook Appoint form Outlook VBA and Custom Forms 2
C Create Meeting With Custom Form Outlook VBA and Custom Forms 2
FryW Need help modifying a VBA script for in coming emails to auto set custom reminder time Outlook VBA and Custom Forms 0
J custom form not displaying pictures Outlook VBA and Custom Forms 7
I Button PDF in Outlook Contact custom form Outlook VBA and Custom Forms 1
K Font Sizing in Custom Form Regions for Contacts Outlook VBA and Custom Forms 1
V Update new custom field Outlook VBA and Custom Forms 5
D Anyone tell me where custom view settings are stored? Outlook VBA and Custom Forms 9
S Outlook 2016 Arrange tasks by date, additional custom sorting, but still use friendly terms like Today, Tomorrow, This week? Using Outlook 1
K can't get custom form to update multiple contacts using VBA Outlook VBA and Custom Forms 3
H Custom Outlook Contact Form VBA Outlook VBA and Custom Forms 1
S Custom Field Cannot Be Displayed In Views Outlook VBA and Custom Forms 2
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

Similar threads

Back
Top