vba for word- how to copy what is on a word doc and paste it on to an outlook email (hopefully to work with both word 2010 and 2003

bleeet

Board Regular
Joined
May 11, 2009
Messages
208
Office Version
  1. 2013
Platform
  1. Windows
hi guys

I want to find out how to copy data (with format) from a word doc and automatically paste it onto an outlook email.

I have this code which worked for word 2010 but the problem is it does not work for 2003. Does anyone happen to have any solution for this?

Code:
Private Sub CommandButton1_Click()CommandButton1.BackColor = 16777215
CommandButton1.ForeColor = 16777215




Dim OutApp As Object
    Dim OutMail As Object
    'Dim OutInsp As Outlook.Inspector
    Dim WdApp As Word.Application
    Dim OutDoc As Word.Document
    Dim WdSel As Word.Selection
       
       




      
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    With OutMail
        .To = ""
        .Subject = ""
        .Display
    End With
    
    Set OutInsp = OutMail.GetInspector
    Set OutDoc = OutInsp.WordEditor
    Set WdApp = OutDoc.Application
    Set WdSel = WdApp.Selection
    
    ActiveDocument.Range.Copy
    WdSel.PasteAndFormat Type:=wdFormatOriginalFormatting
    
    Set WdSel = Nothing
    Set OutInsp = Nothing
    Set OutMail = Nothing
    Set OutDoc = Nothing
    Set WdApp = Nothing
    Set OutApp = Nothing
End Sub

This part of the code gives an error on word 2003 I tried changing references but nothing is working. If anyone has another way please tell me thanks

Set OutInsp = OutMail.GetInspector
Set OutDoc = OutInsp.WordEditor
Set WdApp = OutDoc.Application
Set WdSel = WdApp.Selection
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
I am not an expert but I found this code here: Paste Excel Chart into New Outlook Email

It copied a chart object but I changed that line.

Code:
Sub CopyAndPasteToMailBody()
    Set mailApp = CreateObject("Outlook.Application")
    Set mail = mailApp.CreateItem(olMailItem)
    mail.Display
    Set wEditor = mailApp.ActiveInspector.WordEditor
    ActiveDocument.Range.Copy
    wEditor.Application.Selection.Paste
End Sub

I tried it with Word 2013 and Outlook 2013 and it copied some text and a shape OK.

I hope this helps.
 
Upvote 0
thanks RickXL

but this part of the code does not work with word 2003 :( but it works for word 2010 like my code


wEditor.Application.Selection.Paste

not sure why this is not registering





 
Upvote 0

Forum statistics

Threads
1,225,681
Messages
6,186,411
Members
453,352
Latest member
OrionF

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