Consulting

Results 1 to 16 of 16

Thread: Creating stationary and signatures through code

  1. #1
    BoardCoder
    Licensed Coder
    VBAX Expert mark007's Avatar
    Joined
    May 2004
    Location
    Leeds, UK
    Posts
    622
    Location

    Creating stationary and signatures through code

    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...
    "Computers are useless. They can only give you answers." - Pablo Picasso
    Mark Rowlinson FIA | The Code Net

  2. #2
    VBAX Mentor XL-Dennis's Avatar
    Joined
    May 2004
    Location
    ?stersund, Sweden
    Posts
    499
    Location
    Hi Mark

    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
    Kind regards,
    Dennis

    ExcelKB | .NET & Excel | 2nd edition PED


  3. #3
    BoardCoder
    Licensed Coder VBAX Expert mark007's Avatar
    Joined
    May 2004
    Location
    Leeds, UK
    Posts
    622
    Location
    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?
    "Computers are useless. They can only give you answers." - Pablo Picasso
    Mark Rowlinson FIA | The Code Net

  4. #4
    VBAX Mentor XL-Dennis's Avatar
    Joined
    May 2004
    Location
    ?stersund, Sweden
    Posts
    499
    Location
    Mark,

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

    [vba]
    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
    [/vba]

    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
    Kind regards,
    Dennis

    ExcelKB | .NET & Excel | 2nd edition PED


  5. #5
    BoardCoder
    Licensed Coder VBAX Expert mark007's Avatar
    Joined
    May 2004
    Location
    Leeds, UK
    Posts
    622
    Location
    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!

    "Computers are useless. They can only give you answers." - Pablo Picasso
    Mark Rowlinson FIA | The Code Net

  6. #6
    Just A Dude VBAX Tutor Scottie P's Avatar
    Joined
    May 2004
    Location
    Remote from 18901 USA
    Posts
    263
    Location
    Nice idea!
    Life is Visual: Presence is Perception...
    How we see the world is how we respond to it. ~* Peace *~

  7. #7
    Administrator
    VP-Knowledge Base VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by mark007
    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,
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  8. #8
    BoardCoder
    Licensed Coder
    VBAX Expert mark007's Avatar
    Joined
    May 2004
    Location
    Leeds, UK
    Posts
    622
    Location
    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.

    "Computers are useless. They can only give you answers." - Pablo Picasso
    Mark Rowlinson FIA | The Code Net

  9. #9
    Administrator
    VP-Knowledge Base VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by mark007
    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,

    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!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  10. #10
    BoardCoder
    Licensed Coder
    VBAX Expert mark007's Avatar
    Joined
    May 2004
    Location
    Leeds, UK
    Posts
    622
    Location
    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..
    "Computers are useless. They can only give you answers." - Pablo Picasso
    Mark Rowlinson FIA | The Code Net

  11. #11
    Administrator
    VP-Knowledge Base VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi Mark,

    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.
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  12. #12
    BoardCoder
    Licensed Coder
    VBAX Expert mark007's Avatar
    Joined
    May 2004
    Location
    Leeds, UK
    Posts
    622
    Location
    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!

    "Computers are useless. They can only give you answers." - Pablo Picasso
    Mark Rowlinson FIA | The Code Net

  13. #13
    Administrator
    VP-Knowledge Base VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by mark007
    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,

    Sure I'll do my best to test it this weekend for yah!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  14. #14
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi Mark,

    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! (I love it when it's easy)

    Later...
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  15. #15
    BoardCoder
    Licensed Coder
    VBAX Expert mark007's Avatar
    Joined
    May 2004
    Location
    Leeds, UK
    Posts
    622
    Location
    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?
    "Computers are useless. They can only give you answers." - Pablo Picasso
    Mark Rowlinson FIA | The Code Net

  16. #16
    Administrator
    VP-Knowledge Base VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by mark007
    Ah excellent - will definately try it out when I'm back at work.
    You're welcome I hope it helps with your app.

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

    Which reg keys are you talking about?

    Do you think the same applies for stationary?
    Don't know have to try that. Report on it later when there's time.
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •