VBA copy visible cells to email body below text

Number1One

New Member
Joined
Mar 1, 2019
Messages
16
Office Version
  1. 365
Platform
  1. Windows
Hi All,

Have the below code, almost there, but body text is currently going below the copied table and also want to add a signature.

Code- to copy visible cells in range into email body.

Sub SendEmail()


Dim OutlookApp As Object
'Dim OutlookApp As Outlook.Application
Dim MItem As Object
'Dim MItem As Outlook.MailItem


'Create Outlook object
Set OutlookApp = CreateObject("Outlook.Application")
'Set OutlookApp = New Outlook.Application


Dim Sendrng As Range
Set Sendrng = Worksheets("report").Range("C2:L63").SpecialCells(xlCellTypeVisible)
Sendrng.Copy


'Create Mail Item
Set MItem = OutlookApp.CreateItem(0)
'Set MItem = OutlookApp.CreateItem(olMailItem)
With MItem
.To = "test@email.com"
.Subject = "report"
.CC = ""
.BCC = ""
.Body = "Email body text here"
.Display
End With




SendKeys "^({v})", True
DoEvents
With MItem
'.Send
End With


Set OutlookApp = Nothing
Set MItem = Nothing


End Sub
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Instead of using the SendKeys method, use the WordEditor property of the Inspector object, which returns the Word Document object model...

Code:
With MItem
    .To = "test@email.com"
    .Subject = "report"
    .CC = ""
    .BCC = ""
    .Body = "Email body text here"
    With .GetInspector.WordEditor
        .Application.Selection.EndKey Unit:=6 'wdStory
        .Application.Selection.TypeParagraph
        .Application.Selection.Paste
    End With
    .Display
End With

Hope this helps!
 
Upvote 0
Thanks Domenic, finally got a chance to try it and that does the job great. Can you add a signature in Word mode? :)

Im now needing a second paste into the same email, any help with that?
VBA is running this filter, then copying the resulting visible cells into the above code:
wsDest.Range("$A$4:$BK$750").AutoFilter Field:=8, Criteria1:=Array("Core | Critical", "Core | No"), Operator:=xlFilterValues
wsDest.Range("$A$4:$BK$750").AutoFilter Field:=12, Criteria1:=Array("Today", "Future", "Today Future"), Operator:=xlFilterValues

It now needs to filter again and copy visible cells again in the email, below the other paste with a small gap of body text in between.
wsDest.Range("$A$4:$BK$750").AutoFilter Field:=8, Criteria1:=Array("A", "B", "C"), Operator:=xlFilterValues
wsDest.Range("$A$4:$BK$750").AutoFilter Field:=12, Criteria1:=Array("Today", "Future", "Today Future"), Operator:=xlFilterValues


To create:
Body
Paste 1
Body 2
Paste 2
Signature
 
Upvote 0

Forum statistics

Threads
1,213,496
Messages
6,113,993
Members
448,539
Latest member
alex78

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