Word VBA Question

M

mike

Hi,

I am creating a Word document using VBA. This document is a quote where I
am trying to add a signature based on the user. Each user has an email
signature in Outlook, is there a way to pull this signature into Word?

Thanks
 
E

Ed

Mike:

If this VBA code is to be run on each user's machine, then the code at the
end of this post will open that user's RTF file containing their Outlook
signature and put it in a string. If, however, you are going to create one
of these documents for any other user on your machine, you will need to get
a copy of their signature file and then add an Input Box (or other method)
of determining which user signature you need, and adjust the code
accordingly.

HTH
Ed

Sub Foo_Sig()

Dim strName As String
Dim strFile As String
Dim strFile2 As String
Dim strSig As String
Dim doc1 As Document

' Get UserName
strName = Environ$("Username")
' Name of folder containing sig files
strFile2 = "C:\Documents and Settings\" & _
strName & "\Application Data\Microsoft\Signatures"

' Get rtf sig file
With Application.FileSearch
.LookIn = strFile2
.FileName = "*.rtf"
.Execute

strFile = .FoundFiles(1)
End With

' Name of rtf sig file
strFile2 = "C:\Documents and Settings\" & _
strName & "\Application Data\Microsoft\Signatures\*.rtf"

' Open file and get signature
Set doc1 = Documents.Open(strFile)
strSig = doc1.Content.Text

MsgBox strSig

End Sub
 
E

Ed

Mike - change the last block to
' Open file and get signature
Set doc1 = Documents.Open(strFile)
strSig = doc1.Content.Text
doc1.Close

MsgBox strSig

I forgot to close the sig file!

Ed
 

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