I'm doing something similar to this post but I can't get the email body to format with line breaks and I'd also like to add a signature (stored in outlook). Any help?
Thanks
I'm doing something similar to this post but I can't get the email body to format with line breaks and I'd also like to add a signature (stored in outlook). Any help?
Thanks
Last edited by Leith Ross; 08-31-2011 at 12:50 PM. Reason: added to question
Hello kirtchristensen,
Welcome to the Forum!
I am not sure this extactly what you need but I can easily change it if needed. I had to develop a new macro for what you want to do. This macro will convert the plain text into HTML code and then add on the HTML signature to the email body. Copy and paste this code into a new VBA module in your workbook. You will need to change the body text and the name of the signature file to what you are using . They are marked in bold text.
![]()
' Written: August 31, 2011 ' Author: Leith Ross ' Summary: Converts plain text into HTML code using Word and emails the converted code as the body of the email. ' The user's HTML signature is then added on. Sub EmailTextAndSig() Dim Body As String Dim LineRead As String Dim I As Long Dim N As Long Dim olApp As Object Dim olEmail As Object Dim Sig As String Dim SigFile As String Dim TempFile As String Dim wdApp As Object Dim wdDoc As Object Dim WSH As Object ' Plain text body of email. Body = "This is the first line of text." & vbCrLf & "This is the second line." & vbCrLf _ & vbCrLf & "This is the third line." & vbCrLf f & "This is the fourth line." ' Name of HTML signature file. SigFile = "MySig 1.htm" ' Get the file path to the signature file. Set WSH = CreateObject("WScript.Shell") SigFile = WSH.SpecialFolders("AppData") & "\Microsoft\Signatures\" & SigFile N = FreeFile ' Get the HTML text from the signature file. Open SigFile For Input Access Read As #N Do While Not EOF(N) Line Input #N, LineRead Sig = Sig & LineRead Loop Close #N ' Create a temporary Word file for the plain text that will be converted to HTML. TempFile = Environ("TEMP") & "\" & "Word Temp" Set wdApp = CreateObject("Word.Application") wdApp.Documents.Add Set wdDoc = wdApp.ActiveDocument.Content ' Insert the plain text and save the temporary file as an HTML document. wdDoc.Collapse 0 wdDoc.InsertAfter Body wdApp.ActiveDocument.SaveAs TempFile, 8 wdApp.Quit ' Rename the HTML document as a text file to get the HTML code. Name TempFile & ".htm" As TempFile & ".txt" Body = "" N = FreeFile ' Read the HTML code from the temporary file. Open TempFile & ".txt" For Input Access Read As #N Do While Not EOF(N) Line Input #N, LineRead Body = Body & LineRead Loop Close #N ' Parse the text between the HTML Body tags. I = InStr(1, Body, "<body") N = InStr(I + 1, Body, ">") I = N + 1 N = InStr(I, Body, "</body>") ' HTML code for the plain text body. Body = Mid(Body, I, N - I) ' Delete the temporary file. Kill TempFile & ".txt" ' Start the Outlook program. Set olApp = CreateObject("Outlook.Application") Set olEmail = olApp.CreateItem(0) ' Prepare the email to be sent. With olEmail .To = strto .CC = strcc .BCC = strbcc .Subject = strsub .Importance = 2 'High .HTMLBody = Body & Sig .Send End With End Sub
Last edited by Leith Ross; 08-31-2011 at 10:09 PM. Reason: Changed Email portion to incude OP's settings
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks