<

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x

Standardized Outlook signatures using Active Directory and Word Template

Published on
17,429 Points
11,029 Views
4 Endorsements
Last Modified:
Approved
The advent of Office 365 has forced me back to adding standardized signatures at the client level instead of at the server.  Yes, transport rules will let you add a disclaimer, which can be pressed into service as a signature...but there are many unacceptable limitations.

Whether or not you are using Office 365, you may also need to deploy standardized e-mail signatures at the Outlook client rather than injecting them as they pass through a server.  Sure you can go buy a pricy program to do this, but frankly I don't see much value add for simple Outlook signature management when you can do the same for free with logon scripts.

Some of us know that Outlook signatures can be scripted using various techniques.  Ugly, right?  Not necessarily!  Add a signature template into the mix that even a non-techy can maintain and you have a winning solution!

This article will show you how to create a Word signature template (even the Marketing people can own it with a little training).  The template is then deployed, with individualized user data drawn from Active Directory, with logon scripts.

First, the requirements:

1 -- Microsoft Word and Outlook (the code as written has only been tested with 2010, but should work with other versions as well)
2 -- Active Directory populated with user specific info to include in the signature
3 -- An acceptable location to store the template and the script that is accessible at user logon.



The template itself is a simple Word document with text and graphic elements defining the standard signature.  You can actually have two of these, one for a new email and one for replying.  In places where user-specific information should appear (such as name), a simple placeholder is inserted.  The example code presented recognizes:

  [Name] -- User's full name
  [FirstName] -- User's first name
  [LastName] -- User's last name
  [Title] -- User's title
  [Phone] -- User's telephone number
  [Mobile] -- User's mobile phone number
  [Fax] -- User's fax number
  [Office] -- User's office
  [email] -- User's e-mail address
  [web] -- User's "Web Page" from active directory -- this might be used for something like a users Facebook or LinkedIn page.

So as an example, your Word signature template might look something like this:

ACME Enterprises
       [Name] | [Title]
       Office:  [Phone]
       Mobile: [Mobile]


Additionally, links can be created in the template and replaced with user-specific links.  This one gets a bit strange in Word after the link is created (if you go back and look at it, Word will have replaced the brackets)...but don't worry, it still works.  Let's say you have placed a LinkedIn icon on your standard signature and want it to link to the users LinkedIn profile.  Create the link in the profile as [web] and store the users profile address in Active Directory "Web page".  The code will replace [web] in the link with the appropriate html address.


Now the code*  This is VB Script, so should be saved in a file that ends with ".vbs" (ie createsig.vbs)

------------------------------------------------------------------------------------------------------------------
'Option Explicit
On Error Resume Next
'==================================================
'Create Outlook signature from Word template
'==================================================

'----- Declarations -----
Const wdWord = 2
Const wdParagraph = 4
Const wdExtend = 1
Const wdCollapseEnd = 0

'--------------------------------------------------------------
'----- Modify these variables appropriately ----
'--------------------------------------------------------------
strTemplatePath = "\\server\Signatures\"
strTemplateName = "ACME_Signature_Template.docx"
strReplyTemplateName = "ACME_Reply_Signature_Template.docx"


'----- Connect to AD and get user info -----'
Set objSysInfo = CreateObject("ADSystemInfo")
Set WshShell = CreateObject("WScript.Shell")

strUser = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUser)

strFirstname = objUser.FirstName
strLastName = objUser.givenName
strInitials = objUser.initials
strName = objUser.FullName
strTitle = objUser.Title
strDescription = objUser.Description
strOffice = objUser.physicalDeliveryOfficeName
strCred = objUser.info
strStreet = objUser.StreetAddress
strLocation = objUser.l
strPostCode = objUser.PostalCode
strPhone = objUser.TelephoneNumber
strMobile = objUser.Mobile
strFax = objUser.FacsimileTelephoneNumber
strEmail = objUser.mail
strWeb = objuser.wWWHomePage

'----- Apply any modifications to Active Directory fields -----
'Use company info page if user does not have a Linked-In account specified
 if strweb = "" Then strweb = "http://www.linkedin.com/company/58654"

'----- Open Word template in read-only mode {..Open(filename,conversion,readonly)} -----
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Open(strTemplatePath & strTemplateName,,True)
Set objEmailOptions = objWord.EmailOptions
Set objSignatureObject = objEmailOptions.EmailSignature
Set objSignatureEntries = objSignatureObject.EmailSignatureEntries


'----- Replace template text placeholders with user specific info -----
SearchAndRep "[Name]", strName, objWord
SearchAndRep "[Title]", strTitle, objWord
SearchAndRep "[Phone]", strPhone, objWord
SearchAndRep "[Mobile]", strMobile, objWord
SearchAndRep "[Fax]", strFax, objWord
SearchAndRep "[OfficePhone]", strOfficePhone, objWord
SearchAndRep "[email]", strEmail, objWord
SearchAndRep "[web]", strWeb, objWord

'----- Replace template hyperlink placeholders with user specific info -----
SearchAndRepHyperlink "[email]", strWeb, objDoc
SearchAndRepHyperlink "[web]", strWeb, objDoc


'----- Set signature in Outlook -----
Set objSelection = objDoc.Range()
objSignatureEntries.Add "Full Signature", objSelection
objSignatureObject.NewMessageSignature = "Full Signature"

'see note below if a different reply signature is desired
objSignatureObject.ReplyMessageSignature = "Full Signature"


'----- Close signature template document -----
objDoc.Saved = TRUE
objDoc.Close
objWord.Quit

'----------------------------------------------------------------------------------------------------
'note...if a different reply signature is desired, copy above code from the 
'open template section.  This time through open 
'the reply template instead.
'-----------------------------------------------------------------------------------------------------


'----- Subrouting to search and replace template text placeholders -----
Sub SearchAndRep(searchTerm, replaceTerm, WordApp)
    WordApp.Selection.GoTo 1
    With WordApp.Selection.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .MatchWholeWord = True
        .Text = searchTerm
        .Execute ,,,,,,,,,replaceTerm
    End With
End Sub


'----- Subrouting to search and replace template hyperlink placeholders -----
'         Note this can be picky...if it does not work re-create hyperlink in the template
Sub SearchAndRepHyperlink(searchLink, replaceLink, WordDoc)
	Set colHyperlinks = WordDoc.Hyperlinks
	For Each objHyperlink in colHyperlinks
	    If objHyperlink.Address = searchLink Then                                
        	objHyperlink.Address = replaceLink
            End If
	Next
End Sub
---------------------------------------------------------------------------------------------------------------

Open in new window



Note that you can easily modify the above code to pull basically anything out of Active Directory for use in signatures.  I have selected what seems to be the most common user-variable signature elements.


Now to make it all work!  Create the appropriate network area and be sure security permissions allow all users to access the Word template and run the script.  Depending on your overall philosophy of logon scripts, you may elect to simply place them in the NETLOGON directory.

Next, modify your user logon script(s) to call the code above.  Or if you do not already have logon scripts, just use the create signature code as your logon script.  Again, depending on your organization and overall scripting philosophy you may choose to use Group Policy scripts or simply a User Profile logon script.  Either will work.

Now Outlook signatures will be set (and updated) every time a user logs on -- allowing you to easily push out and modify as necessary standardized e-mail signatures.
4
Author:mds-cos
2 Comments

Expert Comment

by:Kenneth V
My doc temp is looking very nice, but when I run this there is more space between the lines.
1
LVL 1

Expert Comment

by:Robert Chad
Hi this works great thanks, i have one other item i would like to add but cant for the life of me work it out

i want to pull the Photo form the users AD profile and add it to the signature is this possible ? any help appreciated
1

Featured Post

Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
There may be issues when you are trying to access Outlook or send & receive emails or due to Outlook crash which leads to corrupt or damaged PST file. To eliminate the corruption from your PST file, you need to repair the corrupt Outlook PST file. U…
Other articles by this author

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month