Vba loop through each sheet in workbook, paste all into email address in active sheet

DSEIDEN76

New Member
Joined
Oct 8, 2018
Messages
11
VBA rookie back for help. Not sure if what I'm trying to do is possible (or at least as simple as I'm trying to make it).
I have a workbook where I have a macro that splits a main sheet into new sheets based on unique email addresses. I now want to email each sheet based on the email address in cell C2 of each sheet. Would prefer to copy all visible cells in the sheet and paste into .HTMLBody but if I have to save and attach that is okay too. Currently my code is opening Outlook and using the email address in cell C2 of the last sheet, rather than looping through each sheet, and it isn't pasting anything. Thank you in advance for your help.

Code:
Sub
Dim rng As Range
Dim OutApp As Object
Dim OutMail As Object
Dim Work As Worksheet
Dim Lastrow As String


Lastrow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row






Set rng = Nothing
On Error Resume Next
Set rng = ActiveSheet.Range("A1:D" & Lastrow).Select
On Error GoTo 0


With Application
     .EnableEvents = False
     .ScreenUpdating = False
End With


Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)


On Error Resume Next


With OutMail
For Each Work In Worksheets
    .To = ActiveSheet.Range("C2")
    .CC = "test@ferguson.com"
    .Subject = "Test RGA Request"
    .HTMLBody = rng & ActiveSheet.PasteSpecial
    .Display
Next Work
End With
On Error GoTo 0


With Application
     .EnableEvents = True
     .ScreenUpdating = True
End With




   
   
End Sub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Kenneth, thank you for sharing Ron's link. I used that to create much of my code, but I don't understand how to call the function into the sub. He has a function and a sub that don't seem to work in tandem.
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,426
Members
448,961
Latest member
nzskater

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