PDA

View Full Version : Creating stationary and signatures through code



mark007
08-25-2005, 08:28 AM
How can you create a signature and stationary item through vba? Had a quick look through the object model and couldn't see anything that looked appropriate...

XL-Dennis
08-25-2005, 11:09 AM
Hi Mark :hi:

It's a little bit weird when it comes to Outlook and VBA as many things is not programatically available and a workaround is to call the execute command of a command bar.

Sue Mosher excellent site have a nice example that may be workable for You:
http://www.outlookcode.com/codedetail.aspx?id=234

Kind regards,
Dennis

mark007
08-25-2005, 02:58 PM
Thanks Dennis, good to see you around. It was the signature I was more interested in though and more a case of adding the signature to Outlook rather than selecting it for a particular mail i.e. I have an html file I'd like to use as a signature so somehow need to programmatically create a new signature in Outlook called 'MySig' based on this template html file. So that then when I create a new message I can goto insert/signature/mysig as appropriate.

Any ideas?

XL-Dennis
08-25-2005, 03:39 PM
Mark,

OK, let see if this will be more relevant for You:


Option Explicit
Sub Add_Sig()
Const stPFile As String = "c:\Sign.htm"
Dim olApp As Outlook.Application
Dim olItem As Outlook.MailItem
Set olApp = New Outlook.Application
Set olItem = olApp.CreateItem(olMailItem)
With olItem
.Recipients.Add ("bill@xltest.com")
.Subject = "To Mark"
.HTMLBody = Read_Sign(stPFile)
'.Save
.Display
'.Send
End With

Set olItem = Nothing
Set olApp = Nothing
End Sub
Private Function Read_Sign(ByVal stFile As String) As String
Dim fso As Scripting.FileSystemObject
Dim tso As Scripting.TextStream

Set fso = New Scripting.FileSystemObject
Set tso = fso.GetFile(stFile).OpenAsTextStream(1, -2)

Read_Sign = tso.ReadAll

tso.Close
Set tso = Nothing
Set fso = Nothing

End Function


This is a revised version of a recent post at Dick Kusleika's blog Daily Dose of Excel.
If it works then give Dick the credit and not me ;)

Take care and all the very best from,
Dennis

mark007
08-25-2005, 07:16 PM
Hmm, had thought of something along those lines. Problem is I want users to be able to select the sig as and when and also preview it.

To give you the full picture - what I'm after is a way of automatically setting up users staionary and signature so that I can pass a little app round to everyone in the company to set their sig up for them. Currently I have one that creates the html templates and puts them in the relevant folders but now I need to get them selected to save me spending ages on the phone talking people through it!

:)

Scottie P
08-25-2005, 07:21 PM
Nice idea!

MOS MASTER
08-26-2005, 12:53 PM
How can you create a signature and stationary item through vba? Had a quick look through the object model and couldn't see anything that looked appropriate...

Hi Mark,

My 2 cents, why not:


Have the users create there own signatures via the normal way in Outlook.
Add a custom button to show a custom form with a combo or listbox to choose the signature they want.
The combo reads the Signature file names from: "C:\Documents and Settings\USERNAME\Application Data\Microsoft\Signatures
After they make a choise you can:

Read that signature with FSO.OpenTextFile and use the GetUserName API to find the correct path of the file
Than put that in the HTMLBody like Dennis showed yah.
Wouldn't that work?

HTH, :moosegrin

mark007
08-30-2005, 02:31 AM
Have the users create there own signatures via the normal way in Outlook.

That's the problem - they don't know how to! If I could tell them all to do that based on my templates then all would be fine!

The registry key sounds interesting though - that's the sort of thing I'm after. If I can point a key there to my template files then hopefully the signature will be available.

:)

MOS MASTER
08-30-2005, 10:56 AM
That's the problem - they don't know how to! If I could tell them all to do that based on my templates then all would be fine!
Hi Mark, :yes

True but then you could write your custom HTML files to: "C:\Documents and Settings\USERNAME\Application Data\Microsoft\Signatures"

That's the path I gave you before where Outlook stores his Sigs after you create them. So you can pick them up from there (As well the right sigs of people who do know how to make a signature)



The registry key sounds interesting though - that's the sort of thing I'm after. If I can point a key there to my template files then hopefully the signature will be available.

:)

I think it would work just fine from the filepath I gave you before but I you'd like me to I could search the right Reg Key for that part? (I'm sure it's in the Registry)

Good luck! :whistle:

mark007
08-30-2005, 06:43 PM
I have the keys that are needed to specify which signatures should be applied for new mails and replies/forwards. The problem is can't find any info on actually registering a new signature with Outlook as a given name. If I just copy the files to the sig directory I'm fairly sure they won't automatically be available - I will have to check though..

MOS MASTER
08-31-2005, 03:34 PM
Hi Mark, :yes

Ok I'm starting to understand where your going to. (Not fully yet)
But I think it could still work. Like you I have to test it to be sure.

If I find the time I'll test it and report back. :whistle:

mark007
09-02-2005, 01:49 AM
I've not had chance to test and am off work this week so won't be able to (I don't use or have Outlook setup at home). If you do get chance to have a play around I would therefore appreciate it!

:)

MOS MASTER
09-02-2005, 10:13 AM
I've not had chance to test and am off work this week so won't be able to (I don't use or have Outlook setup at home). If you do get chance to have a play around I would therefore appreciate it!

:)

Hi Mark, :yes

Sure I'll do my best to test it this weekend for yah! :hi:

MOS MASTER
09-02-2005, 01:42 PM
Hi Mark, :yes

This is very funny.

When I go to: "C:\Documents and Settings\Admin\Application Data\Microsoft\Handtekeningen" (My dir for signatures)

I see my signature: (Three files) Joost.rtf ; Joost.txt ; Joost.htm (So one for each mailtype outlook supports!

When I just copy them and rename them to Joost_Test.rtf etc...and I reopen outlook and want to add a sig that signature: "Joost_Test" is available to me.

So writing the files to that directory is enough to register the file with Outlook! :rofl: :yes (I love it when it's easy)

Later...:whistle:

mark007
09-02-2005, 02:35 PM
Ah excellent - will definately try it out when I'm back at work.

That combined with the reg keys I know about should do the job.

Do you think the same applies for stationary?

MOS MASTER
09-03-2005, 10:15 AM
Ah excellent - will definately try it out when I'm back at work.


You're welcome I hope it helps with your app.



That combined with the reg keys I know about should do the job.[/quote

Which reg keys are you talking about?

[quote]
Do you think the same applies for stationary?

Don't know have to try that. Report on it later when there's time. :yes