navid86
asked on
Insert signature in Outlook 2003 at users cursor via VBA
I have found how to insert a signature using VBA and it works fine. But, now I was wondering if it is possible to insert the signature at the users cursor in the email. Currently the signature appends to the bottom of the email, but my users are now having difficulty with it when they reply or forward emails. So, I would like to see if I can insert the signature where the user has but the cursor instead of appending it at the bottom of the email.
Below is the current code I have for the signatures. One method I have used to insert text in the path was the "SendKey" function in VBA, but I am not sure how to do this with signatures.
Below is the current code I have for the signatures. One method I have used to insert text in the path was the "SendKey" function in VBA, but I am not sure how to do this with signatures.
Sub InsertSignature()
Dim objFSO As Object, _
objShell As Object, _
objSignatureFile As Object, _
olkMsg As Outlook.MailItem, _
strSigFilePath As String, _
strBuffer As String
Set olkMsg = Application.ActiveInspector.CurrentItem
Set objShell = CreateObject("Wscript.Shell")
strSigFilePath = objShell.SpecialFolders("Desktop")
If InStr(1, WinVer(), "Vista") Then
strSigFilePath = Replace(strSigFilePath, "Desktop", "AppData\Roaming\Microsoft\Signatures\")
Else
strSigFilePath = Replace(strSigFilePath, "Desktop", "Application Data\Microsoft\Signatures\")
End If
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Edit the signature file name on the following line as needed'
Set objSignatureFile = objFSO.OpenTextFile(strSigFilePath & "NXW-FIRM.htm")
strBuffer = objSignatureFile.ReadAll
objSignatureFile.Close
olkMsg.HTMLBody = olkMsg.HTMLBody & strBuffer
Set objSignatureFile = Nothing
Set objFSO = Nothing
Set objShell = Nothing
Set olkMsg = Nothing
End Sub
Function WinVer() As String
Dim objShell As Object, strOS As String, strKey As String
Set objShell = CreateObject("WScript.Shell")
strOS = objShell.ExpandEnvironmentStrings("%OS%")
If strOS = "Windows_NT" Then
strKey = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\"
WinVer = objShell.RegRead(strKey & "ProductName") & " " & objShell.RegRead(strKey & "CurrentVersion") & "." & objShell.RegRead(strKey & "CurrentBuildNumber")
Else
strKey = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\"
WinVer = objShell.RegRead(strKey & "ProductName") & " " & objShell.RegRead(strKey & "VersionNumber")
End If
Set objShell = Nothing
End Function
ASKER
Okay, thanks!
Hope to hear from you soon!
Hope to hear from you soon!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sweet man!!! Works like a Charm!! I wish I could give you more than the 500 points for this!!
I do have a simple question though. The code that I copied from Microsoft into a new module comes up as a macro name, "CopySigtoClipboard". Is there anyway I can hide this from the Macro list?
Thanks again for everything!!
I do have a simple question though. The code that I copied from Microsoft into a new module comes up as a macro name, "CopySigtoClipboard". Is there anyway I can hide this from the Macro list?
Thanks again for everything!!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Works AMAZING!
Thank you sooo much for your help!!
Thank you sooo much for your help!!
ASKER
Thanks a lot for your help! I have noticed that you have helped on some of my past issues and I really like how you follow through till the issue is complete!!!
Thanks
Thanks
Thanks and you're welcome. Always happy when I can help out.
You can't use this kind of script to insert text at the cursor location in Outlook 2003 because Outlook doesn't expose the cursor location. SendKeys will work, but it limits you to plain text, no HTML or graphics. There might be another way to accomplish this, but I'll have to test my theory before I know for sure.