| Code level: advanced Code area: Outlook Expert Techniques Printer Friendly Version | ||
| Title: Insert user signature with VBA | ||
| Description: This sample for both the built-in Outlook editor and WordMail demonstrates how to use CommandBars techniques to insert a known, named signature into the current email message. In particular, it demonstrates that WordMail in Outlook 2002/3 uses a bookmark named _MailAutoSig to handle signatures. See notes below for known issues. | ||
| Date: 26-Oct-2004 10:22 | ||
| Code level: advanced | ||
| Code area: Outlook Expert Techniques | ||
| Posted by: Sue Mosher | ||
| Body: |
||
| All 128comments |
| Page [ 1 2 3 4 5 6 7 8 9 10 Next >> ] | ||
|
|
Sue Mosher
26-Oct-2004 17:25
NOTES: 1) This code is for Outlook 2002/2003 VBA only. Note that in Outlook 2002 SP3, it will trigger a security prompt. 2) It requires references in Tools | References to the Office and Word libraries. 3) **** The operation of the built-in Outlook editor seems inconsistent. Sometimes it works fine and sometimes it inserts the last signature used, rather than the named signature specified. I'm baffled by this. 4) Usage: Sub InsertMySig() Call InsertSig("Name of your signature") End Sub where "Name of your signature" is the exact name of the signature as it appears on the signature menus and dialogs. |
|
|
|
Melissa
24-Nov-2004 14:08
I recently wrote a simple macro for a group of users at my firm who need particular text added to any email message they send to the group. I gave them each custom signatures because the text needed to be formatted when using RTF or HTML. My macro is in the Application_ItemSend macro. To insert the signature if the message passes the criteria I used the code Item.GetInspector.CommandBars.Item("Insert").Controls("Signature").Controls("Confidential MacroInsert").Execute This works perfectly on my computer but, of course, has a problem when installed elsewhere. On my computer the "signature" is inserted at the beginning of the body, before the text. Not the usually place for a signature I know but exactly what I needed. On other users' computers the signature is inserted at the end of the document. I can not find any settings that are different. Any ideas on what might be different or how I can control where the signature is placed? It is firm policy that users can not use WordMail formats so the bookmark references in this email will not work for me. Thanks. |
|
|
|
Sue Mosher
25-Nov-2004 08:29
Outlook itself provides no way to set the insertion point in a message that isn't using WordMail. You could try using SendKeys to position it. |
|
|
|
Jerry V
04-Dec-2004 17:47
It works great, but it comes out in a font I don't use. Just inserting signature with regular insert signature command does that too. Is there a line of code I can add to set the font to Comic Sans? I tried finding a property to do that, but it didn't work, perhaps because I had it attached to wrong object. |
|
|
|
Anonymous
04-Dec-2004 20:05
Sounds like you need to edit your signature. Make sure it's in Comic Sans and has a blank line before it. |
|
|
|
Jerry V
05-Dec-2004 08:02
The signature is formatted in the desired font and has a line in front of it. The signature seems to appear in whatever font the header appears in. Would like to have line of code to force it to my font. |
|
|
|
Anonymous
05-Dec-2004 08:48
It's not something you can do in a single line of code. If you're using Outlook's built-in email editor, you'd need to use the SafeInspector object from the Redemption library (http://www.dimastr.com/redemption/ ). If you're using Word as your email editor, you have the option of recording a macro that runs in Word VBA. |
|
|
|
klubell
17-Jan-2005 14:22
Try this (it works only with Outlook 2002): Uses registry to find the Outlook Signature file and then reads it itno a string Function GetOutlookSignature() As String Dim oShell As Object Dim bRegKey On Error GoTo ErrHandler '-- Read from Registry the Default Signature Name Set oShell = CreateObject("WScript.Shell") bRegKey = oShell.RegRead("HKCU\Software\Microsoft\Office\10.0\Common\MailSettings\NewSignature") '-- Get Application Data Directory Dim sAppDataDir As String sAppDataDir = oShell.SpecialFolders("AppData") '-- Read the Default Signature from a file Dim strSignaturePath As String, strHTML As String strSignaturePath = sAppDataDir + "\Microsoft\Signatures\" + bRegKey + ".htm" Const ForReading = 1, ForWriting = 2 Dim fso As Object, f As Object Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.OpenTextFile(strSignaturePath, ForReading) strHTML = f.ReadAll f.Close '-- Parse out Body Dim iStart As Integer, iEnd As Integer iStart = InStr(LCase(strHTML), "<body>") + Len("<Body>") iEnd = InStr(LCase(strHTML), "</body>") MsgBox strHTML GetOutlookSignature = "<br><br>" + Mid(strHTML, iStart, iEnd - iStart) MsgBox GetOutlookSignature GoTo ExitHandler ErrHandler: MsgBox Err.Description, vbCritical, "GetOutlookSignature" ExitHandler: Set oShell = Nothing Set fso = Nothing Set f = Nothing End Function |
|
|
|
Jerry M
27-Jan-2005 07:02
Does anyone know how to insert a date in a mail message? I would like to have a new message created with today's date at the top of the e-mail and a Signature at the bottom. Any ideas? ---------------------------------------------------------------------------- Line 1 : 27 January Line 2: Line n: Signature |
|
|
|
Sue Mosher
27-Jan-2005 08:32
Jerry, you didn't say anything about the version of Outlook or whether you're using WordMail as the email editor or what format messages you want to support. All of these things matter. |
|
| Page [ 1 2 3 4 5 6 7 8 9 10 Next >> ] | ||
| Post your comment name email |
