ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Copy and Paste from Excel into Outlook Email message (https://www.excelbanter.com/excel-programming/316276-copy-paste-excel-into-outlook-email-message.html)

TroyB[_2_]

Copy and Paste from Excel into Outlook Email message
 
Hi!

I've got the following example spreadsheet and below code that works ok.



Spreadsheet


A
B
C
D

1
10 Nov 2004
Name
Email
PayAmount

2

Joe Bloggs

$254,365.23

3

Bart Simpson

$325.35

4

Wilma Rubble

$2,253.35




VBA Code

'Using Outlook2003 and Excel2003

'For this code to work, you need to Select Tools-- References --

' Tick box - Microsoft Outlook 11.0 Object Library



Sub Send_EmailMsg()

Dim objOL As New Outlook.Application

Dim objMail As MailItem

Dim NoOfStaff As Integer, a As Integer, rwIndex As Integer, colIndex As
Integer



NoOfStaff = Range("Email").Rows.Count

rwIndex = 2

colIndex = 2



For a = 1 To NoOfStaff



Set objOL = New Outlook.Application

Set objMail = objOL.CreateItem(olMailItem)



PayPerson = Cells(rwIndex, colIndex).Value

PayAmount = Format(Cells(rwIndex, colIndex + 2).Value, "$ #,###.#0")

PayEmail = Cells(rwIndex, colIndex + 1).Value



With objMail

.To = PayEmail

.Subject = PayPerson & " - PaySlip for Paydate " &
Format(Range("A1").Value, "dd mmm yyyy")

.Body = "Please find below payslip information. A value of " & _

PayAmount & " has been deposited into your selected account."



.Display



End With



rwIndex = rwIndex + 1



Set objMail = Nothing

Set objOL = Nothing



Next a



End Sub





What i would prefer, if it could send each person in the Range("Email") an
email that;

1. Copies and pastes cells (say B2:L15) from Sheet2 into the email body
of the first email recipient

2. Then copies and pastes cells (say B17:L30) from Sheet2 into the
email body of the second email recipient

3. etc etc



By "copying" from Excel into the email, all the required formatting, values
etc accompanies the email message, which is what i require.



Alternatively, is it possible to load a specific form in Outlook and the
data from Excel is imported in the fields required?



Thank you in advance

Boeky






All times are GMT +1. The time now is 09:28 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com