How do I setup a signature select prompt when sending mail

G

Guest

Hi,

I need to programm Outlook 2003 in such way that it will prompt the user to
chose a signature from a list of signatures before it send the mail. This
action has to be triggered as soon as the user hit the send button.

Thanks
 
G

Guest

You can definitely do this. To hook into the Send event, see this article:

Eric Legault My Eggo : Getting a Handle on Your E-mails with VBA:
http://blogs.officezealot.com/legault/pages/20086.aspx

Getting specific signature text to insert can be achieved with this function
- replace the signature file name with one you know exists:

Function GetSignatureText() As String
Dim objFS As New Scripting.FileSystemObject, objTS As Scripting.TextStream
Dim objF As Scripting.Folder, strSysDrive As String
Dim strUserName As String, strSigText As String

Set objF = objFS.GetSpecialFolder(0)
strSysDrive = Left(objF, 1)
strUserName = FindUserName
Set objTS = objFS.OpenTextFile(strSysDrive & ":\Documents and Settings\"
& strUserName & "\Application Data\Microsoft\Signatures\Work.txt" _
, ForReading, False)
strSigText = objTS.ReadAll
End Function

But ultimately you need to parse out the uniquely named .rtf, .txt and .html
files in that folder to present the user with a list of signatures. Then
take the selection to call a modified function like the one above to return
the actual text. Then append that value to the MailItem.Body property.
 
G

Guest

Hi Eric,

Thanks a lot for the help. I set the macro according to the article that you
mentioned bellow and now I can trigger functions as I want. I am midway
through setting the multuple signatures and getting a form to display the
list of signatures.

Thanks again for the help.
Regards
Dinesh
Cheers
 
S

Sue Mosher [MVP-Outlook]

That sounds like a different question. Please clarify what you're trying to do.
 
G

Guest

I'm trying to use the signature (if there are more than one) that was set as
default - I mean the one that is normally added to the message.

I believea good way out is to find out which of the signature files is the
newest one and to use it. I wrote the following code (basing on previous
response):

Private Function GetSignatureText() As String
Dim objFSO As New FileSystemObject, objFTO As Scripting.TextStream
Set objFTO = objFSO.OpenTextFile(NewestSignatureFile, ForReading, False,
TristateUseDefault)
GetSignatureText = objFTO.ReadAll
objFTO.Close
End Function
Private Function NewestSignatureFile() As String 'finds the newest file
Dim q As Integer, strTempFileStore As String, intFileMod As Integer,
strAppUsName As String

strAppUsName = Application.UserName

With Application.FileSearch
.LookIn = "C:\Documents and Settings\" & strAppUsName &
"\Application Data\Microsoft\Signatures"
.Filename = "*.txt"
If .Execute > 0 Then

If .FoundFiles.Count = 1 Then
NewestSignatureFile = .FoundFiles(1)
Exit Function
End If

If .FoundFiles.Count > 1 Then
intFileMod = DateDiff("d", Date, FileDateTime(.FoundFiles(1)))
NewestSignatureFile = .FoundFiles(1)
For q = 1 To .FoundFiles.Count
If intFileMod < DateDiff("d", Date,
FileDateTime(.FoundFiles(q))) Then
intFileMod = DateDiff("d", Date,
FileDateTime(.FoundFiles(q)))
NewestSignatureFile = .FoundFiles(q)
End If
Next q
End If
End If
End With

End Function

Is there a better way? A built-in method?
 
S

Sue Mosher [MVP-Outlook]

There is no built-in method. I've done it by creating and displaying a new message, which will contain the user's default signature.

Remember that signatures exist in three files, for the three different mail formats.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 

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