vba excel to Outlook

dshafique

Board Regular
Joined
Jun 19, 2017
Messages
171
Hey Guys, Im trying to create a macros for an application report. the report contains application data and the status if they're expired or not. for each application which is expired, i want to email the whole row of data to the owner and the technician. the names are also in the same row.

Here is what I have so far:
Code:
or Each cl In Range("PAD[PAD ID]")

   Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    On Error Resume Next
    With OutMail
        .To = ActiveCell.Offset(0, 2).Value
        .CC = ActiveCell.Offset(0, 7).Value
        .BCC = ""
        .Subject = "CIO Ticket Automation test"
        .HTMLBody = ThisWorkbook.Sheets("PAD").Range("A2:K2").Value
        ' In place of the following statement, you can use ".Display" to
        ' display the e-mail message.
        .Display
    End With
    On Error GoTo 0
    
    With Application
        .EnableEvents = True
        .ScreenUpdating = True
    End With
   Next cl

i get the "to" value from the 3rd column of my table and my "cc:" value from the 8th column. but everytime i run this loop, it only puts the people from my first row in outlook every run. and it doesnt put anything in the body for the email.

i am fairly new to vba with outlook, any and all support would be greatly appreciated. :)
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
1. Move the createobject line to before the loop.
2. Replace ActiveCell with cl.
3. Use Ron de Bruin's RangeToHTML() to convert a range to well, html.

https://www.rondebruin.nl/win/s1/outlook/bmail2.htm

If you need help building the range for RangeToHTML(), post back. Obviously, you would use cl.Row as part of that. e.g.
Code:
.htmlBody = RangeToHTML(Range("A" & cl.row, "E" & cl.Row)))
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
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