0

There are many posts about how to add a default signature in drafting a new email in outlook by VBA.

However, is there any way to choose which signature to insert in the email? I am writing a VBA to copy data from excel and then draft a new email in outlook with non-default signature.

Many thanks!

5
  • Why not just enter the closing "signature" programmatically instead of using a "saved signature"? Commented Feb 6, 2018 at 4:06
  • ... I have not done it myself, but I know the bookmark Bookmarks("_MailAutoSig") would be involved. Might be helpful to search for examples with that. Commented Feb 6, 2018 at 4:10
  • the signature is composed of several pictures and texts. it will be better to use saved signature Commented Feb 6, 2018 at 5:14
  • 1
    ...I don't understand: either way you're adding it programmatically, and can be re-used whether it's saved as a "signature", or saved as a Sub... Commented Feb 6, 2018 at 5:21
  • are you aware that you can save signatures without VBA? Commented Feb 7, 2018 at 3:45

1 Answer 1

1

In order to include a non-standard signature you would need to open the signature template from the %AppData%\Microsoft\Signatures folder, and append the contents of the appropriate file to your message body.

.... 'Your other code to create the mailitem "msg" goes here.'

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(Environ("AppData") & "\Microsoft\Signatures\mySig2.htm", ForReading)
strText = objTextFile.ReadAll
objTextFile.Close

msg.HTMLBody = msg.HTMLBody & strText
Sign up to request clarification or add additional context in comments.

3 Comments

thanks for your help, however it shows that run time error 5: invalid procedure call or argument when i run the line *Set objTextFile = objFSO.OpenTextFile("%AppData%\Microsoft\Signatures\mySig2.htm", ForReading)
i tested the htm link works but the whole line does not work
@rlau You may need to add a reference to your project for the Windows Script Host Object Model (wshom.ocx)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.