Help! Sending Excel range via Outlook using sendkeys

DEE_715

New Member
Joined
Feb 12, 2014
Messages
10
Hi all,

Im not the greatest with Excel VBA but i have put together a small programme to send an excel range via an Outlook email using send keys and then to return to excel and do something else.

The progamme works perfectly in isolation (Excel to Outlook -End)

But when i add excel code to the bottom (Excel to Outlook to Excel-End) the range that i have copied from excel does not paste into the Email body (Send keys ..."v"), so the email sends to the correct address, subject etc but the body is blank.

I get the impression something is clearing the clipboard or the sendkeys "v" is pasting somewhere else and i think it has something to do with adding the final Excel code at the end.


Any help would be greatly appreciated :eeek: . Code below



Sub test()

Mystring1 = Range("A1")
Sheets("Sheet1").Select
Rows("1:1").Select
Selection.AutoFilter
ActiveSheet.Range("$A$1:$G$502841").AutoFilter Field:=7, Criteria1:= _
Mystring1
Range("A1:G502841").Select
Selection.Copy
Sheets("Sheet3").Select
Range("A2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

Dim objOutlook As Object
Dim objMail As Object
Dim rngTo As Range
Dim rngCc As Range
Dim rngSubject As Range
Dim rngBody As Range

Set objOutlook = CreateObject("Outlook.Application")
Set objMail = objOutlook.CreateItem(0)


With Sheets("Sheet3")
Set rngTo = .Range("I1")
Set rngCc = .Range("I2")
Set rngSubject = .Range("I3")
Set rngBody = .Range("A1:G10")
End With

rngBody.Copy
With objMail
.To = rngTo.Value
.Cc = rngCc.Value
.Subject = rngSubject.Value
.Display

End With
With objMail
SendKeys "^({v})", True
SendKeys "%({S})", True

End With
Set objOutlook = Nothing
Set objMail = Nothing
Set rngTo = Nothing
Set rngCc = Nothing
Set rngSubject = Nothing
Set rngBody = Nothing

Sheets("Sheet2").Select
Rows("1:1").Select
Selection.Delete Shift:=xlUp

End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Forum statistics

Threads
1,223,098
Messages
6,170,106
Members
452,302
Latest member
TaMere

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