Sending email based on filtered cells only

VBAWannabee2

New Member
Joined
Feb 23, 2022
Messages
28
Office Version
  1. 2010
Platform
  1. Windows
Hi! Hoping everyone is doing well.
I'm in need of help on my mini-code.
I'm trying to work on sending a set/range of cells from A:F as picture in Outlook and it works.
However, it won't stop generating an email even though the next line/row doesn't have a value. (It was filtered by Column I)
Also, how can it capture the header plus the details? (see picture 2 for reference)
Any help will do, thanks and cheers!

VBA Code:
Sub Z()

Dim OutApp As Object
Dim Outmail As Object
Dim cell As Range
Dim rng As Range
Dim table As Range
Dim pic As Picture
Dim sh As Worksheet
Dim wordDoc

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

Set sh = Sheets("2022")

' email recipient
For Each cell In sh.Columns("H").cells.SpecialCells(xlCellTypeVisible)

Set rng = sh.cells(cell.Row, 1).Range("A1:F1").SpecialCells(xlCellTypeVisible)

Set OutApp = CreateObject("Outlook.Application")

Set Outmail = OutApp.CreateItem(0)
  
    Set table = rng
    sh.Activate
    table.Copy
    Set pic = sh.Pictures.Paste
    pic.Cut

strbody = "<p>Test Email</p>"

With Outmail
        .To = cell.Value
        .Subject = "Test"
        .Display

Set wordDoc = Outmail.GetInspector.WordEditor
            With wordDoc.Range
                .InsertParagraphAfter
                .PasteAndFormat wdChartPicture
                .InsertParagraphAfter

            End With
          
        .HTMLBody = "<BODY style = font-size:10.5pt; font-family;Arial>" & _
            strbody & .HTMLBody
      
    End With

Next cell

MsgBox "Process complete!"
  
Set OutApp = Nothing
Set Outmail = Nothing
  
End Sub
 

Attachments

  • 1653286995926.png
    1653286995926.png
    23.5 KB · Views: 27
  • 1653287099098.png
    1653287099098.png
    11.5 KB · Views: 19

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

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