Trying to Copy and Paste Excel Range to Outlook but Paste Not Working

larssonkok

New Member
Joined
Nov 27, 2023
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hi,

I am trying to create a VBA code to create a new Outlook email and paste a range from my Excel file to the body of the email. Everything is working up until the paste piece. The correct cells are copied in the clipboard and I can paste it to the email by CTRL+V after the macro runs but I cannot get the data to paste as part of the running code. I am absolutely not an expert in vba or writing code and have put this together by lots of googling and watching tutorials.

My code is below and everything up until the last piece where I am trying to paste works. I would appreciate any guidance as I'm banging my head against a wall at this point!

Sub Macro3()
'
' Macro3 Macro
'

'
Dim oLookApp As Outlook.Application
Dim oLookItm As Outlook.MailItem
Dim oLookIns As Outlook.Inspector

Dim oWrdDoc As Word.Document
Dim oWrdRng As Word.Range


Dim ExcRng As Range


On Error Resume Next

Set oLookApp = GetObject(, "Outlook.Application")
If Err.Number = 429 Then
Set oLookApp = New Outlook.Application

End If

Set oLookItm = oLookApp.CreateItem(olMailItem)
Set ExcRng = Sheet6.Range("A7:J180")

With oLookItm

.Subject = Range("A2").Value
.To = "123@dummyemail.com"
.CC = "123@dummyemail.com"
.Body = ""

.Display

Set oLookInsp = .GetInspector
Set oWrdDoc = oLookIns.WordEditor

ExcTbl.Range.Copy
Set oWrdRng = oWrdDoc.Application.ActiveDocument.Content
oWrdRng.Collapse Direction:=wdCollapseEnd

Set oWrdRng = oWrdDoc.Paragraphs.Add
oWrdRng.InsertBreak

ExcRng.Copy

oWrdRng.PasteAndFormat wdFormatOriginalFormatting


End With

End Sub
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Hi *larssonkok and Welcome to the Board! Your code requires a Word process be running with a document open... do you have this going on? There's really no need to use Word. You can paste ranges directly from XL to your outlook message. See this link for an example. HTH. Dave
ps. please use code tags
 
Upvote 0

Forum statistics

Threads
1,224,821
Messages
6,181,163
Members
453,021
Latest member
Justyna P

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