Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Want to have email message insert signature with VBA

Status
Not open for further replies.

kjv1611

New member
Jul 9, 2003
10,758
US
I used a rendition of the code found in this thread:
thread702-396121

It works very well. However, when using this, it does not give the option to insert a signature (I have my signature done in Word, and use Word for editing emails).

What I would like to be able to do is one or both of the following:
1.) With a email message created all from code, insert my default email signature.

2.) Use a template email which I have (for Outlook 2003) stored under "User File Tempates on File System".

Any suggestions would be greatly appreciated.

Thanks!
 
Does this need to insert other user's signatures? And what kind of info does the signature contain?

I think the best way to tackle this would be through code.

It would be pretty easy to set up a combo box on the form for Emailer's Name, and have that linked to table containing email address, department, title, Phone Number and whatever else you need in the signature. Then set up a string containing each value where Name = EmailersName and place it at the end of your .Body after a few CrLf's.

Hope this helps,

Alex
 
as far as your signature goes, KJV,
is it simply a matter of opening the word doc, you have it in, then copying and pasting, so to speak?
I'll wait for a response, before I offer some word Automation.
 
Well, what I would prefer would be to just insert the default signature that is already present in Outlook, so that regardless of who uses it, the signature automatically works correctly. I realize I could just hard-code it into the email, but then that would require storing user information in the database which would mean more maintenance in the future, possibly. I can think of a way to do such in an automated manner, except for having to add/remove users as time progresses, which is something I want to stay away from with this one.

Is there any way via Word or Outlook automation that I can look at using the default signature (the same signature that automatically gets added to emails when you are using Outlook as email editor and/or the one that gets automatically inserted when not using Word as the email editor.

Thanks for the suggestions so far, but I would prefer to do something like this if possible.
 
kjv, here's a possible start.

Code:
Sub InsertSig(strSigName As String)
    Dim objItem As Object
    Dim objInsp As Outlook.Inspector
    ' requires a project reference to the
    ' Microsoft Word library
    Dim objDoc As Word.Document
    Dim objSel As Word.Selection
    ' requires a project reference to the
    ' Microsoft Office library
    Dim objCB As Office.CommandBar
    Dim objCBP As Office.CommandBarPopup
    Dim objCBB As Office.CommandBarButton
    Dim colCBControls As Office.CommandBarControls
    On Error Resume Next
    
    Set objInsp = Application.ActiveInspector
    If Not objInsp Is Nothing Then
        Set objItem = objInsp.CurrentItem
        If objItem.Class = olMail Then  ' editor is WordMail
            If objInsp.EditorType = olEditorWord Then
                ' next statement will trigger security prompt
                ' in Outlook 2002 SP3
                Set objDoc = objInsp.WordEditor
                Set objSel = objDoc.Application.Selection
                If objDoc.Bookmarks("_MailAutoSig") Is Nothing Then
                    objDoc.Bookmarks.Add Range:=objSel.Range, Name:="_MailAutoSig"
                End If
                objSel.GoTo What:=wdGoToBookmark, Name:="_MailAutoSig"
                Set objCB = objDoc.CommandBars("AutoSignature Popup")
                If Not objCB Is Nothing Then
                    Set colCBControls = objCB.Controls
                End If
            Else ' editor is not WordMail
                ' get the Insert | Signature submenu
                Set objCBP = Application.ActiveInspector.CommandBars.FindControl(, 31145)
                If Not objCBP Is Nothing Then
                    Set colCBControls = objCBP.Controls
                End If
            End If
        End If
        If Not colCBControls Is Nothing Then
            For Each objCBB In colCBControls
                If objCBB.Caption = strSigName Then
                    objCBB.Execute ' **** see remarks
                    Exit For
                End If
            Next
        End If
    End If
    
    Set objInsp = Nothing
    Set objItem = Nothing
    Set objDoc = Nothing
    Set objSel = Nothing
    Set objCB = Nothing
    Set objCBB = Nothing
End Sub

here's the site & credits,

good luck
 
Thanks, Zion7, I'll take a look at this, and see if I can use it in whole or part, and post back - may be next week....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top