Heh - I know I don't work for you because you don't pay me anything!
Anyway, it is not a problem - I love doing this stuff.
Below is everything you need. This approach bypasses the need for an .oft
file. All you need to change is the name of the attachment that is being
auto-inserted into the reply, and the name of the signature as it appears in
the Insert -> Signature menu.
The first two procedures differ so that you map the first one to a toolbar
in the Outlook window, and the other to a toolbar in an e-mail window.
Rock and roll!
Option Explicit
Public Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" _
(ByVal lpBuffer As String, nSize As Long) As Long
Sub ReplyWithTemplateFromOutlook()
If ActiveExplorer.Selection.Count = 0 Or ActiveExplorer.Selection.Count
'No selected e-mail message to respond to, or too many selected -
should only select one
Exit Sub
End If
If ActiveExplorer.Selection.Item(1).Class <> olMail Then
'Only reply to e-mail items
Exit Sub
End If
ReplyToCurrentMessage ActiveExplorer.Selection.Item(1)
End Sub
Sub ReplyWithTemplateFromEmail()
If ActiveInspector Is Nothing Then
'No open e-mail message to respond to!
Exit Sub
End If
If ActiveInspector.CurrentItem.Class <> olMail Then
'Only reply to e-mail items
Exit Sub
End If
ReplyToCurrentMessage ActiveInspector.CurrentItem
End Sub
Private Sub ReplyToCurrentMessage(MessageToReply As Outlook.MailItem)
Dim objReply As Outlook.MailItem
Dim strSignatureText As String
Set objReply = MessageToReply.Reply
'Insert a particular signature by calling function with the name of the
signature from the Insert -> Signature menu
strSignatureText = GetSignatureTextByName("webadmin")
'Insert signature at the beginning of reply body text
'If signatures are already automatically inserted, this will insert a
second signature!!! no way around this
objReply.Body = strSignatureText & vbCrLf & objReply.Body
'Auto insert the file you want attached
objReply.Attachments.Add "C:\Temp\test.txt", OlAttachmentType.olByValue
objReply.Display
Set objReply = Nothing
End Sub
Function GetSignatureTextByName(SignatureName As String) As String
Dim objFS As New Scripting.FileSystemObject, objTS As Scripting.TextStream
Dim objF As Scripting.Folder, strSysDrive As String
Dim strUserName As String
Dim strExtension 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\" & SignatureName _
& ".txt", ForReading, False, TristateFalse)
If objTS Is Nothing Then Exit Function
GetSignatureTextByName = objTS.ReadAll
objTS.Close
Set objTS = Nothing
Set objFS = Nothing
Set objF = Nothing
End Function
Public Function FindUserName() As String
Dim strBuffer As String
Dim lngSize As Long
strBuffer = String(100, " ")
lngSize = Len(strBuffer)
If GetUserName(strBuffer, lngSize) = 1 Then
FindUserName = Left(strBuffer, lngSize)
Else
Exit Function
End If
'ELIMINATES NULL CHARACTERS
FindUserName = Replace(FindUserName, Chr(0), "")
End Function
--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
Try Picture Attachments Wizard for Outlook!
http://tinyurl.com/ckytm
Job:
http://www.imaginets.com
Blog:
http://blogs.officezealot.com/legault/