macro to copy cells from spreadsheet in Outlook email

marinica

New Member
Joined
Jun 23, 2011
Messages
5
Hi guys,

how can you write a macro to copy cells from spreadsheet and paste them in the body of an Outlook email?
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
I am sure there are other methods but I concatenate cells to do this.
You need to enter the first/last Row, first/last column.
(You could code for dynamic rows/column numbers)

Code:
Sub Send_Email()
 
Dim EmailSubject As String
Dim SendTo As String
Dim EmailBody As String
Dim ccTo As String
 
EmailSubject = "Test"
SendTo = "[EMAIL="test@yahoo.co.uk"]test@yahoo.co.uk[/EMAIL]"
 
 
FirstRow = 1 
LastRow = 5
FirstCol = 1 
LastCol = 2 
 
For r = FirstRow To LastRow
For c = FirstCol To LastCol
 
For Each cell In Cells(r, c)
strtable = strtable & "  " & cell.Value
Next
Next
strtable = strtable & vbNewLine
Next
 
EmailBody = "Hi" & vbLf & vbLf & " body of message you want to add" & vbLf & vbLf & strtable & vbNewLine 
 
Set App = CreateObject("Outlook.Application")
Set Itm = App.CreateItem(0)
With Itm
.Subject = EmailSubject
.To = SendTo
.CC = ccTo
.Body = EmailBody
.Display
'.Send
End With
Set App = Nothing
Set Itm = Nothing
End Sub
 
Upvote 0
Hi daverunt,

Thank you very much.:)

It worked and I needed to adjust a bit the formating.

I am wondering if you actual can copy a part of spreadsheet and paste it in Outlook as a picture (or as table with the same format as you have set up in EXCEL)

cheers
 
Upvote 0
I had to delete the last two posts because of trouble with the HTML that I couldn't fix.
 
Upvote 0
Sorry about that John, I forgot the HTML tags and used code tags and it threw a wobbly.

The gist of the post was just about adding a border to the table in Outlook.

HTML:
 <table Border =1>
 
Upvote 0

Forum statistics

Threads
1,224,566
Messages
6,179,555
Members
452,928
Latest member
101blockchains

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