April 2, 2007
Now that we’ll go further with this. How to push these settings enterprise-wide.
As we added line break to the document, we can continue to fill the signature and put (a last!) the name of the company we work in. The procedure is absolutely the same except that for now we are typing company name and hence we are passing the that out mysterious company ACME Corporation name to the input of the method:
objSelection.TypeText “ACME Corporation”
After that we are running Range() to end with the typed text selection block.
Now when we created the content of the signature we are stepping in to create the signature in Outlook. First off we need to create the object that will represent the parent of the object representing the signature. That means we should create objEmailOptions object:
Set objEmailOptions = objWord.EmailOptions
Alright, the parent is created, lets create the child, the objSignatureObject object:
Set objSignatureObject = objEmailOptions.EmailSignature
Now when we created the objSignatureObject signature object that’s the time to include our signature to the list of signatures. What’s the list? It’s the collection. Want to know how it looks like?
1. Open Outlook
2. Open Tools|Options and switch to the Mail Format tab on the Options dialog box
3. In the Signatures section click Signatures button to open the Create Signature dialog box
4. Here we are. The collection is just the list of items listed in the Signature list in this dialog
To create the collection we need to create object
Set objSignatureEntries = objSignatureObject.EmailSignatureEntries
We are ready to fill in the list now. To do that we need to add new item to the collection by using the Add method. To name it somehow we’ll just pass Standard Signature as the parameter:
objSignatureEntries.Add “Standard Signature”, objSelection
Let’s check what we created. Open the Create Signature dialog box as stated in the list above (see step 3) and check the Standard Signature is in the list of available signatures (or the only existing one if you haven’t created the single one yet).
“Wait, wait, wait, wait!” I hear you are saying that. “You told us about the name of the signature, but how did we create it?” You are right. We used reference to the created objSelection object to fill in the signature with the text. That’s what we used Word for.
OK. Signature is created, we can go. Unfortunately, not yet. You are asking, why? Look at the Signature section on the Mail Format tab in the Options dialog box. Observe two drop-down lists there. We haven’t assigned the signature yet. We need to make sure that when the user will either create or reply to the message the created signature will be used there. To do that we need to use two corresponding properties.
1. NewMessageSignature property is used to attach new signature to all newly created messages
2. ReplyMessageSignature property will be used in case user will reply to the incoming message
Lets go. As always, we are creating two objects:
objSignatureObject.NewMessageSignature = “Standard Signature”
objSignatureObject.ReplyMessageSignature = “Standard Signature”
Now look at the mentioned drop-down lists. The “Standard Signature” item is there and successfully selected. Try to create new mail or reply to the message. You will get the created signature attached at the bottom of your message.
By the way, if we would have another signature in the list of signatures we could set another one as the default either for new message or for the replied one depending on what you want it to be by typing its name within the quotes.
Voila! We ended with signature creation. That wasn’t too complicated tasks but still… Look at what we did? Can we leave this alone? Can we consider it to be the right solution? Of course, not. First of all we are talking about corporate environment with computers joined to domain. If we will stop with this solution it would require us either create a set of unique signature scripts, or create a huge IF branching that would put different names for signatures to make them unique for all user computers.
I’ll continue describing what we can do. For now you can find the ways right in the list of the articles I put at the bottom of this my note. See you later.
MSDN Magazine Scripting Outlook Signature article
How about automation? Automatic E-mail Signatures Creation
How to find and use Office object model documentation
Programming the Outlook object model
Microsoft Word Object Model
The TypeText Method
Microsoft Word Selection Object Members
What’s new in Outlook 2007 Object Model
Technorati tags: object model ADSI script outlook object model word object model exchange properties signature generate personal signature mail signature active directory scripting Microsoft Office outlook profiles corporate mail VBScript