Auto-email with picture in the body mail.

VBAWannabee2

New Member
Joined
Feb 23, 2022
Messages
28
Office Version
  1. 2010
Platform
  1. Windows
Hi! I'm figuring out ways on how to auto-create an email with a picture/table in it. (range of cells in excel)

Objective: Auto-email with picture in a bodymail.
Issue/Error: The line after the list were also included in the creation of email but it shouldn't because it's just a blank cell.
This is my code, I'm just restructuring some codes from my previous work.

Also see attached picture of the email. (Image 1 = issue/errorr, Image 2 = list, Image 3 = objective)
Any help will do! Thanks!!

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("Sheet1")

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

Set rng = sh.cells(cell.Row, 1).Range("A1:G1").Offset(1, 0)

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
1655774492758.png

1655774638275.png

1655774759860.png
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Forum statistics

Threads
1,215,054
Messages
6,122,895
Members
449,097
Latest member
dbomb1414

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