{"id":12162,"date":"2012-10-11T16:00:45","date_gmt":"2012-10-11T16:00:45","guid":{"rendered":"http:\/\/www.learnexcelmacro.com\/?p=2442"},"modified":"2022-08-12T11:32:13","modified_gmt":"2022-08-12T11:32:13","slug":"insert-outlook-signature-in-email","status":"publish","type":"post","link":"https:\/\/vmlogger.com\/excel\/2012\/10\/insert-outlook-signature-in-email\/","title":{"rendered":"How to insert Outlook Signature in Email by Excel VBA"},"content":{"rendered":"
In this Article you are going to learn how to insert Outlook Signature in outlook email while sending an email via Excel VBA. It means while sending an email from Outlook via Excel Macro, if you want already saved signature to be inserted at the end of your email, then here is the code to do so. These files get stored at the following location in your system: Windows 7 and 8 :<\/strong> \n<\/td>\n<\/tr>\n<\/table>\n Note: <\/strong> Signature<\/p><\/div>\n <\/p>\n In the below code we are first checking if these files exists and have some values in it. If yes then we are reading the text from the signature file and inserting that signature in the email. \nFunction to read the Signature file and return the Signature Text<\/strong><\/p>\n <\/p>\n Below is the code to create the Outlook Email with the Signature at the end. <\/strong> <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n If your signature contains some image, then above method will not display the image in signature. You will see that all the texts are displayed in signature but not the image. <\/p>\n To overcome this issue, there are two solutions.. refer to my new article<\/a><\/p>\n<\/span>","protected":false},"excerpt":{"rendered":" In this Article you are going to learn how to insert Outlook Signature in outlook email while sending an email via Excel VBA. It means while sending an email from Outlook via Excel Macro, if you want already saved signature to be inserted at the end of your email, then here is the code to […]<\/p>\n","protected":false},"author":45,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[5205,1676],"tags":[],"class_list":["post-12162","post","type-post","status-publish","format-standard","hentry","category-send-email","category-excel-tips"],"yoast_head":"\n
\n
\n<< Return to Send Email Tutorial Page<\/strong><\/a>
\n <\/p>\n\n
\n \n
\nImportant:<\/strong>
\n \n<\/td>\n<\/tr>\n\n \nAs soon as you create a signature in Outlook it saves the signature in 3 different types of files: .HTM, TXT and RTF<\/strong> as shown below:
\n<\/p>\n
\n
\nWindows XP :<\/strong>
\nC:\\Documents and Settings\\Vish\\Application Data\\Microsoft\\Signatures
\n <\/p>\n
\nC:\\Users\\Vish\\AppData\\Roaming\\Microsoft\\Signatures<\/p>\n
In the below code when we are creating an email in Outlook then at the end of the email, we will insert the Signature from the .txt<\/strong> file or .htm<\/strong> file.
\n<\/p>\n
\nThus we need a function which read and return the Signature Texts from the file wherever we need to insert it in the body of the Outlook email.<\/p>\n\n\nFunction GetSignature(fPath As String) As String\n Dim fso As Object\n Dim TSet As Object\n Set fso = CreateObject(\"Scripting.FileSystemObject\")\n Set TSet = fso.GetFile(fPath).OpenAsTextStream(1, -2)\n GetSignature= TSet.readall\n TSet.Close\nEnd Function\n\n<\/code><\/pre>\n
\nHere there could be two types of Email and Signatures:<\/p>\n\n
\nWe will see the code of both the above methods below one by one:<\/p>\nEmail and Signature with Simple Text<\/h2>\n
\nSub With_Text_Signature()\n\n 'Do not forget to change the email ID\n 'before running this code\n\n Dim OlApp As Object\n Dim NewMail As Object\n Dim EmailBody As String\n Dim StrSignature As String\n Dim sPath As String\n\n Set OlApp = CreateObject(\"Outlook.Application\")\n Set NewMail = OutApp.CreateItem(0)\n\n EmailBody = \"Type the Body of your email\"\n\n '*****************************************************\n ' Important\n '*****************************************************\n ' go to the appdata path as mentioned in\n ' the above important point. Check the name of\n ' the signature file. For example: here in my system\n ' the signature's file name is vish.txt, vish.htm\n ' Therefore before running this code, check the\n ' name fo the signature file in your system and\n ' replace vish.txt with your file name.\n '****************************************************\n\n sPath = Environ(\"appdata\") & \"\\Microsoft\\Signatures\\vish.txt\"\n\n ' If the path and file name given by you is not\n ' correct then code you insert a blank Signature\n \n If Dir(sPath) <> \"\" Then\n StrSignature = GetSignature(sPath)\n Else\n StrSignature = \"\"\n End If\n\n On Error Resume Next\n With NewMail\n .To = \"info@learnexcelmacro.com\"\n .CC = \"info@learnexcelmacro.com\"\n .BCC = \"info@learnexcelmacro.com\"\n .Subject = \"Type your Subject here\"\n ' Here at the end of the Email Body\n ' Text Signature is inserted.\n .Body = EmailBody & vbNewLine & vbNewLine & StrSignature\n .send\n End With\n On Error GoTo 0\n Set NeMail = Nothing\n Set OlApp = Nothing\nEnd Sub\n<\/code><\/pre>\n
Email and Signature with HTML Body and HTML Signature<\/h2>\n
\nSub With_HTML_Signature()\n\n 'Do not forget to change the email ID\n 'before running this code\n\n Dim OlApp As Object\n Dim NewMail As Object\n Dim EmailBody As String\n Dim StrSignature As String\n Dim sPath As String\n\n Set OlApp = CreateObject(\"Outlook.Application\")\n Set NewMail = OlApp.CreateItem(0)\n \n ' Here Since we are talking about\n ' the HTML email then we need to\n ' write the Body of the Email in\n ' HTML.\n\n EmailBody = \"Hello Friends !!\" & \"
Welcome to LearnExcelMacro.com\" & vbNewLine & _\n \"Here i will make you awesome in Excel Macro.
You can mail me at info@learnexcelmacro.com\"\n\n '*****************************************************\n ' Important\n '*****************************************************\n ' go to the appdata path as mentioned in\n ' the above important point. Check the name of\n ' the signature file. For example: here in my system\n ' the signature's file name is vish.txt, vish.htm\n ' Therefore before running this code, check the\n ' name of the signature file in your system and\n ' replace vish.txt with your file name.\n '****************************************************\n\n sPath = Environ(\"appdata\") & \"\\Microsoft\\Signatures\\vish.htm\"\n\n ' If the path and file name given by you is not\n ' correct then code you insert a blank Signature\n \n If Dir(sPath) <> \"\" Then\n StrSignature = GetSignature(sPath)\n Else\n StrSignature = \"\"\n End If\n\n On Error Resume Next\n With NewMail\n .To = \"info@learnexcelmacro.com\"\n .CC = \"info@learnexcelmacro.com\"\n .BCC = \"info@learnexcelmacro.com\"\n .Subject = \"Type your Subject here\"\n ' Here at the end of the Email Body\n ' HTML Signature is inserted.\n .htmlBody = EmailBody & \"
\" & StrSignature\n .send\n End With\n On Error GoTo 0\n Set NeMail = Nothing\n Set OlApp = Nothing\nEnd Sub\n\n<\/code><\/pre>\nImportant : Outlook Signature with an Image<\/h2>\n