Import Text from word to outlook

Kellogg

New Member
Joined
Mar 30, 2013
Messages
41
Platform
  1. Windows
  2. MacOS
Dear Great Minds of Excel,

I have a spreadsheet that that I log business type contacts from. I can email from the spreadsheet to anyone of my contacts listed. I want to be able to place text in the outlook email but preserve the formatting. I can import the text from a word file by it I converted to text only with out formatting. I have the code below that allows the user to select the file and copy to a variable named MsgTxt. When outlook email is created the text does not include formatting.

Here is what worked without the formatting.


HTML:
'Dimension variables.
 Dim OL As Object, MailSendItem As Object
 Dim W As Object
 Dim MsgTxt As String, SendFile As String
 Dim ToRangeCounter As Variant
'Identifies Word file to send
 SendFile = Application.GetOpenFilename(Title:="Select MS Word " & _
     "file to mail, then click 'Open'", buttontext:="Send", _
     MultiSelect:=False)
 'Starts Word session
 Set W = GetObject(SendFile)

'Pulls text from file for message body
 MsgTxt = W.Range(Start:=W.Paragraphs(1).Range.Start, _
    End:=W.Paragraphs(W.Paragraphs.Count).Range.End)
'Ends Word session


Thanks for any suggestions.


/s/


Craig
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Dear Great Minds of Excel,

I could not find a way to delete and start over so I'm replying to my original info with a better explanation. I want to send an email via excel that embeds a files content after the email body is created. Excel sets up the initial addressee and then I'm asked to open a file on my computer and the file is inserted after the body created by excel. I have searched and modified code to create the email and copy the file info but it replaces the content of the email body instead of adding to it. If I do not use editor.Content.Paste in the code the email body id preserved but the file is not added. I have included the code I'm using and hope this provides a better explanation. I have removed much of the details to try and simplify. You can use any word file on your computer. I'm using MS Office 2013. Any help would be great. Thanks in advance. - Craig

Code:
Dim objOL   'As Outlook.Application
Dim objAppt 'As Outlook.AppointmentItem
Dim WordApp As Object 'MS WORD
Dim WordDoc As Object 'MS WORD
Dim OutMailEditor As Object 'OUTLOOK
Dim EmailWho
Dim EmailHdr As String 
Dim ActMessage As String
Dim MsgNot1 As String
Dim MsgNot2 As String
Dim MsgNot3 As String
'    '
'SET UP EMAIL Info
'
    MsgString = “First Name “ & “Last Name” & "
" & _
    “Title” & "
" & _
    “Organization” & "
"
   
    EmailHdr = "Just Checking In"
    ActMessage = "" & "For Your Information " & "" & "" & “Request Below” & "" & "
" & "
" & "
" & ""
 
    MsgNot1 = "Dear Recipient, "  & "
" & "
"
    MsgNot2 = "Your infor is provided below" & "
" & "
"
    MsgNot3 = "Yada yada yada" & "
" & "
"
'
'
'IMPORT TEXT FROM WORD FILE IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
‘IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
'Dimension variables.
 Dim OL As Object, MailSendItem As Object
 Dim W As Object
 Dim MsgTxt As String, SendFile As String
 
'Identifies Word file to send
 SendFile = Application.GetOpenFilename(Title:="Select MS Word " & _
     "file to mail, then click 'Open'", buttontext:="Send", _
     MultiSelect:=False)
 
 'Starts Word session
 Set W = GetObject(SendFile)
 W.Content.Copy
 
'Pulls text from file for message body
 MsgTxt = W.Range(Start:=W.Paragraphs(1).Range.Start, _
    End:=W.Paragraphs(W.Paragraphs.Count).Range.End)
'
‘
'Ends Word session IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
'
'
'Create EMAIL
'EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
    EmailSubject = “Email Subject"
    DisplayEmail = True 
    Email_To = “EmailWho” 
    Email_CC = ""
    Email_BCC = ""
    strbody = MsgString '
'
' ******************************************************
'
    Set OutlookApp = CreateObject("Outlook.Application")
    Set OutlookMail = OutlookApp.CreateItem(0)
    Set WordApp = CreateObject("Word.Application")
    Set OutlookAttachment = OutlookMail.Attachments   
'
'
    With OutlookMail
'
'
 
        .To = EmailWho 'Addressee
        .CC = ""  'Email_CC
        .BCC = "" 'Email_BCC
        .Subject = “Subject”
        .htmlbody = strbody & "
" & _
            ActMessage & _
   
            "/s/" & "
" & "
" & _
            “WhoSent” & "
" & _
            "Company Name"  & "
"
           
‘After html info is in email I want to embed word file I copied to clipboard and preserve formatting.  ‘However, the embedded file should appear after the html body and not replace it.
‘When I include the following
       
        Set editor = .GetInspector.WordEditor
        editor.Content.Paste
        .Display
 
'The formatted file is displayed in the email body but everything else is replaced.  
''''
''''
    End With
'EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
 
Upvote 0
Dear Great Minds of Excel,

I could not find a way to delete and start over so I'm replying to my original(s) info with a better explanation. Mr. Editor please delete my second post. I tried but the ten minute limit passed.

I want to send an email via excel that embeds a files content after the email body is created. Excel sets up the initial addressee and then I'm asked to open a file on my computer and the file is inserted after the body created by excel. I have searched and modified code to create the email and copy the file info but it replaces the content of the email body instead of adding to it. If I do not use editor.Content.Paste in the code the email body id preserved but the file is not added. I have included the code I'm using and hope this provides a better explanation. I have removed much of the details to try and simplify. You can use any word file on your computer. I'm using MS Office 2013. Any help would be great. Thanks in advance. - Craig

Code:
Dim objOL   'As Outlook.Application
Dim objAppt 'As Outlook.AppointmentItem
Dim WordApp As Object 'MS WORD
Dim WordDoc As Object 'MS WORD
Dim OutMailEditor As Object 'OUTLOOK
Dim EmailWho
Dim EmailHdr As String 
Dim ActMessage As String
Dim MsgNot1 As String
Dim MsgNot2 As String
Dim MsgNot3 As String
'    '
'SET UP EMAIL Info
'
    MsgString = “First Name “ & “Last Name” & "<br>" & _
    “Title” & "<br>" & _
    “Organization” & "<br>"
'   
    EmailHdr = "Just Checking In"
'
    ActMessage = "<font color=""Blue"">" & "For Your Information " & "</font>" & "<font color=""black"">" & “Request Below” & "</font>" & "<br>" & "<br>" & "<br>" & ""
'
    MsgNot1 = "Dear Recipient, "  & "<br>" & "<br>"
    MsgNot2 = "Your infor is provided below" & "<br>" & "<br>"
    MsgNot3 = "Yada yada yada" & "<br>" & "<br>"
'
'
'IMPORT TEXT FROM WORD FILE IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
‘IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
'Dimension variables.
 Dim OL As Object, MailSendItem As Object
 Dim W As Object
 Dim MsgTxt As String, SendFile As String
 
'Identifies Word file to send
 SendFile = Application.GetOpenFilename(Title:="Select MS Word " & _
     "file to mail, then click 'Open'", buttontext:="Send", _
     MultiSelect:=False)

 'Starts Word session
 Set W = GetObject(SendFile)
 W.Content.Copy

'Pulls text from file for message body
 MsgTxt = W.Range(Start:=W.Paragraphs(1).Range.Start, _
    End:=W.Paragraphs(W.Paragraphs.Count).Range.End)
'
‘
'Ends Word session IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
'
'
'Create EMAIL
'EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
    EmailSubject = “Email Subject"
    DisplayEmail = True 
    Email_To = “EmailWho” 
    Email_CC = ""
    Email_BCC = ""
    strbody = MsgString '
'
' ******************************************************
'
    Set OutlookApp = CreateObject("Outlook.Application")
    Set OutlookMail = OutlookApp.CreateItem(0)
    Set WordApp = CreateObject("Word.Application")
    Set OutlookAttachment = OutlookMail.Attachments   
'
'
    With OutlookMail
'
'
        .To = EmailWho 'Addressee
        .CC = ""  'Email_CC
        .BCC = "" 'Email_BCC
        .Subject = “Subject”
        .htmlbody = strbody & "<br>" & _
            ActMessage & _
            "/s/" & "<br>" & "<br>" & _
            “WhoSent” & "<br>" & _
            "Company Name"  & "<br>"
            
‘After html info is in email I want to embed word file I copied to clipboard and preserve formatting.  ‘However, the embedded file should appear after the html body and not replace it.

‘When I include the following
        
        Set editor = .GetInspector.WordEditor
        editor.Content.Paste
        .Display

'The formatted file is displayed in the email body but everything else is replaced.  
''''
''''
    End With
 
Upvote 0

Forum statistics

Threads
1,215,343
Messages
6,124,400
Members
449,156
Latest member
LSchleppi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top