How to change signatures using VBA?

M

Mueller Michael

Hi.

After buying the book "Microsoft Outlook Programming" some of my problems
were resolved easily, but now i'm stuck with changing signatures using VBA.

Till now I haven't found any solution for changing the signature to a
specific one (out of four) within the Outlook-settings or change the
signature while generating a new Mail, like using a parameter pointing to
the wanted sig.

Can some of you help me out?

Thanks
Michi
 
M

Michael Bednarek

After buying the book "Microsoft Outlook Programming" some of my problems
were resolved easily, but now i'm stuck with changing signatures using VBA.

Till now I haven't found any solution for changing the signature to a
specific one (out of four) within the Outlook-settings or change the
signature while generating a new Mail, like using a parameter pointing to
the wanted sig.

Can some of you help me out?

I suggested a solution not so long ago in
<http://groups.google.fi/[email protected]>.

At its shortest, it might look like this:

strBody = strBody & CreateObject("Scripting.FileSystemObject").OpenTextFile(strSigFile, ForReading).ReadAll

It might help to remember that normally signature files are stored in
%USERPROFILE%\Application Data\Microsoft\Signatures
 
M

Mueller Michael

Till now I haven't found any solution for changing the signature to a
I suggested a solution not so long ago in
<http://groups.google.fi/[email protected].
gbl>.

At its shortest, it might look like this:

strBody = strBody & CreateObject("Scripting.FileSystemObject").OpenTextFile(strSigFile,
ForReading).ReadAll

It might help to remember that normally signature files are stored in
%USERPROFILE%\Application Data\Microsoft\Signatures

Hi Michael.

This solution is quite nice, but only for pure textmails. I have to deal
with formated text.
but it's good to see were the signatures are stored, maybe this will be
helpful in the future.

Some clues how to add formated sigantures?

Thanks
Mihci
 
M

Mueller Michael

Can some of you help me out?

Hi Sue.

Thanks for your reply.
For now I create a new mail, and then I insert the sig. This works quite
well.
Problem is, that the cursor itself stays behind the signature.
But it should stay at first position in the body, like
cursor
empty line
signature

How can I change the cursorposition within the body buy sending a
'STRG+Pos1'?
Do you have a fix for this one, too?

Thanks
Michi
 
S

Sue Mosher [MVP-Outlook]

The methods available depend on whether you're using WordMail as the editor, in which case you can set the insertion point with Word methods, or the built-in Outlook editor, in which case you either use a SendKeys kludge or the Redemption SafeInspector.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
M

Mueller Michael

How can I change the cursorposition within the body buy sending a
'STRG+Pos1'?
Do you have a fix for this one, too?

Steps should be like:
- insert blank line in body
- jump to the end of the body
- insert signature
- jump to the start of the body

Thanks
Michi
 
M

Michael Bednarek

Hi Michael.

This solution is quite nice, but only for pure textmails. I have to deal
with formated text.
but it's good to see were the signatures are stored, maybe this will be
helpful in the future.

Some clues how to add formated sigantures?

It works here for HTML-formatted messages as well; I don't see why it
wouldn't work for RTF - you just have to pick the right signature file.
 
J

John Gregory

I always run this procedure from an XL module. This procedure will pu
any signature from the OL2K menus for Inbox, Tools, Options, Mai
Format, drop down box in the Body or any signature there can b
hardcoded into the macro to put in the Body. It will put th
signature at the top or bottom or anywhere in the Body. It will als
concatenate parts of the Body from an XL worksheet, hard coded macr
text and the signatures in OL. I do not know if it is forwar
compatible with XL2003, but if not maybe the techniques can b
modified to work. I tested this code dozens of times before postin
it

Sub MailItem_3_With_Signature_From2ndOlMailItemOL2K_JDG(
Dim olApp As Outlook.Applicatio
Dim olSigMailItem As Outlook.MailIte
Dim olMailItem1 As Outlook.MailIte
Set olApp = New Outlook.Applicatio
Set olMailItem1 = olApp.CreateItem(olMailItem
Set olSigMailItem = olApp.CreateItem(olMailItem

If MsgBox(Prompt:="Select default Signature in menus:"
& vbCrLf & vbCrLf &
"Inbox" & vbCrLf &
"Tools" & vbCrLf &
"Options" & vbCrLf &
"Mail Format - Tab" & vbCrLf &
"Use This Signature by Default",
Buttons:=vbOKCancel)
= vbCancel Then GoTo ExitHandle

With olSigMailIte
'Body method will overwrite automatic default signature
'Plain Text never needed in this Signature mail item
'Comment out line below to use default signature
.Body = "" 'Overwrites default Signature, if any
.Display (False) 'Display required, or signature is lost
End Wit

'SIGNATURE FROM OL INBOX TOOLS OPTIONS MAIL FORMA
'ADDED TO BODY OF olSigMailIte
'Comment out to use default signatur
olSigMailItem.GetInspector.CommandBars.
Item("Standard").Controls("&Signature").
Controls("John Gregory").Execute
'Change Signature above to one in your OL Options, Mail Format Tab

With olMailItem
.To = "(e-mail address removed)
.Subject = "Msg Serial Number 0012
'Body part 1 usually in an XL cell with multiple lines & wor
wrap
'Concatenate new text with a Sig from other olMailItem
.Body = "Concatenate this text and the Body, with a "
& "default signature from the other olMailItem"
& vbCrLf & vbCrLf & olSigMailItem.Bod
'.Body = "Concatenate (1) this text (2) XL cells and" &
" (3) Body with signature in another olMailItem"
& vbCrLf & Range("A1")
& vbCrLf & Range("A2")
& vbCrLf & olSigMailItem.Bod
.Displa
.Sav
End Wit

'PLAIN TEXT method works consistently outside With statement
'Inside a with statement, it fails intermittently! Why
'I ran several dozen tests
olMailItem1.GetInspector.CommandBars.Item("Format").
Controls("Plain Text").Execute 'ID=556

olSigMailItem.Delete 'Delete temporary mail item

ExitHandler
Set olApp = Nothin
Set olSigMailItem = Nothin
Set olMailItem1 = Nothin
End Su
 
M

Mueller Michael

Hi John.

Thanks for your piece of code.
.Body = "Concatenate this text and the Body, with a " _
& "default signature from the other olMailItem" _
& vbCrLf & vbCrLf & olSigMailItem.Body

But with this line all formats of the wanted siganture got lost.
It is shown as in default format :(

Michi
 
M

Mueller Michael

Hi Michael.
It works here for HTML-formatted messages as well; I don't see why
it wouldn't work for RTF - you just have to pick the right signature
file.

I have a signature here for testing, containin three lines:
Line1: Fonstsize 12 - Bold - Blue
Line2: Fonstsize 10 - Bold - Black
Line3: Fonstsize 10 - Italic - Black

It surely works with HTML and RTF-Mails, but the formats of the signature is
lost.

Michael
 
M

Mueller Michael

Hi Sue.
or the built-in Outlook editor, in which case you either
use a SendKeys kludge or the Redemption SafeInspector.

Thanks.
Last thing for now: What's the 'Redemption SafeInspector'?

Michi
 
S

Sue Mosher [MVP-Outlook]

Redemption (http://www.dimastr.com/redemption/) is a third-party wrapper around Extended MAPI that offers a lot of functionality not supported in the Outlook object model. Among its key objects is a SafeInspector that offers text selection and formatting techniques that Outlook objects don't support.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
M

Mueller Michael

Redemption (http://www.dimastr.com/redemption/) is a third-
party wrapper around Extended MAPI that offers a lot of
functionality not supported in the Outlook object model.
Among its key objects is a SafeInspector that offers text
selection and formatting techniques that Outlook objects
don't support.

Thanks and a big hug for your help.

Michi
 
M

Michael Bednarek

Hi Michael.


I have a signature here for testing, containin three lines:
Line1: Fonstsize 12 - Bold - Blue
Line2: Fonstsize 10 - Bold - Black
Line3: Fonstsize 10 - Italic - Black

It surely works with HTML and RTF-Mails, but the formats of the signature is
lost.

How do you specify those formatting elements? HTML? RTF?

What is the signature's file extension?

What is you default e-mail format?

What is your default e-mail Editor? MS Word? Outlook?

My e-mail Editor is Outlook; my default e-mail format is HTML; I have an
HTML signature file called mb.htm. When I execute the quoted VBA code,
it inserts the HTML signature into an HTML e-mail, format intact, just
like it does when manually inserting the same signature file.
 
M

Mueller Michael

Hi Michael.

Here we have RTF-Mails and Outlook-singature-editor.
Meanwhile I used the solution Sue provided to me, including a bunch of
sendkeys and now it works flawlessly.

Greetings
Michi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top