Email using VBA in Excel not working

VbaHell

Well-known Member
Joined
Jan 30, 2011
Messages
1,220
Hello all

I hope you can help on this issue please

I am using Outlook 2016 from the Office 365 program

I have three email accounts set up and I am trying to run this code to automatically send out emails from the primary email account

I know this works ok with Microsoft office Outlook but it will not work in my Outlook 2016

Can anyone spot the mistake here please



[Sub SendEmail()


Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
Dim strHTMLBody As String

Application.ScreenUpdating = False

Set OutApp = CreateObject("Outlook.Application")

strHTMLBody = ""
For Each cell In Range("G1:G53")
If Intersect(cell, Range("G14:G24")) Is Nothing Then
strHTMLBody = strHTMLBody & cell.Value
Else
strHTMLBody = strHTMLBody & "<b><i>" & cell.Value & "</b></i>"
End If
Next

On Error GoTo cleanup
For Each cell In Columns("B").Cells.SpecialCells(xlCellTypeConstants)
If cell.Value Like "?*@?*.?*" And _
LCase(Cells(cell.Row, "C").Value) = "yes" Then
Set OutMail = OutApp.CreateItem(0)
'On Error Resume Next
With OutMail
.To = cell.Value
.Subject = "Bla Bla bla"
.Attachments.Add "C:\Users\Joe Bloggs\Pictures.jpg"
.HTMLBody = "Attention " & Cells(cell.Row, "A").Value & strHTMLBody & "<br><img src=""cid:AGL.jpg"">"
.Send
End With
'On Error GoTo 0
Set OutMail = Nothing
End If
Next cell

cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True




End Sub]
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Forum statistics

Threads
1,223,907
Messages
6,175,300
Members
452,633
Latest member
DougMo

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