VBA - Email Body not sending

kirstieruchat

New Member
Joined
Oct 23, 2017
Messages
4
Hi,

I am using the below VBA to try and send an email. The email is sending but there is no body in the email. It is just and email with a subject line.

Any help please?

Thanks
Kirstie

VBA Code:
Sub TESTEmailSender()
    Dim OutApp As Object
    Dim OutMail As Object
    
    Application.ScreenUpdating = False
    Set OutApp = CreateObject("Outlook.Application")


            Set OutMail = OutApp.CreateItem(0)
            On Error Resume Next
            With OutMail
                .To = "email@email.com"
                .Subject = Sheet6.Range("B6").Value & " - " & "SDH Price Increase"
                .Body = "Entity: " & Sheet6.Range("I3").Value & _
                        vbNewLine & vbNewLine & _
                        "Customer Email: " & Sheet6.Range("I7").Value & _
                        vbNewLine & vbNewLine & _
                        "Sales Manaager Email: " & Sheet6.Range("I10").Value & _
                        vbNewLine & vbNewLine & _
                        vbNewLine & vbNewLine & _
                        vbNewLine & vbNewLine & _
                        vbNewLine & vbNewLine & _
                        vbNewLine & vbNewLine & _
                "Dear " & _
                       vbNewLine & vbNewLine & _
"You last updated the NBRT on " & Cells(cell.Row, "F").Value & "." & vbLf & Cells(cell.Row, "G").Value & _
                        vbNewLine & vbNewLine & _
                        Cells(cell.Row, "E").Value & _
                        vbNewLine & vbNewLine & _
                        Sheet10.Range("G30").Value & _
                        vbNewLine & vbNewLine & _
                        "Many Thanks," & _
                        vbNewLine & vbNewLine & _
                        "K"
         
                   
    .Send
   
End With
            On Error GoTo 0
            Set OutMail = Nothing
      
cleanup:
    Set OutApp = Nothing
    Application.ScreenUpdating = True
End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Remove the On Error Resume Next line and see what is happening. Perhaps you have errors in some of the cells.
 
Upvote 0
Remove the On Error Resume Next line and see what is happening. Perhaps you have errors in some of the cells.
This has helped me to find there is errors. I have stripped it all back.

when i do this: .Body = "Entity: " & Sheet6.Range("I4").Value & vbNewLine & "Customer Email: " it worked perfectly but when I add the next piece of code on: .Body = "Entity: " & Sheet6.Range("I4").Value & vbNewLine & "Customer Email: " & Sheet6.Range("I7").Value it stops working - any idea what I am doing wrong?
 
Upvote 0
What is in I7 on that sheet when the code is running?
 
Upvote 0
That shouldn't be a problem. What exactly does "stops working" mean?
 
Upvote 0
Your Code, shortened down a little bit, as it's only tested on ActiveSheet.
And I have used HTML, to show the example, which gives you a bit more opportunities, to refine the Text.
It should work by you.

VBA Code:
Sub TESTEmailSender()
    Dim OutApp As Object
    Dim OutMail As Object
    
    Application.ScreenUpdating = False
    Set OutApp = CreateObject("Outlook.Application")


            Set OutMail = OutApp.CreateItem(0)
            On Error Resume Next
            With OutMail
                .To = "email@email.com"
                .Subject = ActiveSheet.Range("B6").Value & " - " & "SDH Price Increase"
                                
                .HTMLBody = "<font face=""calibri"" style=""font-size:12pt;""Entity: " & ActiveSheet.Range("I3").Value & _
                        "<br><br>" & _
                        "Customer Email: " & ActiveSheet.Range("I7").Value & _
                        "<br><br>" & _
                        "Sales Manager Email: " & ActiveSheet.Range("I10").Value & _
                        "<br><br>" & _
                        "<br><br>" & _
                        "Many Thanks" & _
                        "<br>" & _
                        "Kirstie" & _
                        .HTMLBody & "</font>"

                   
    .Send
   
End With
            On Error GoTo 0
            Set OutMail = Nothing
      
cleanup:
    Set OutApp = Nothing
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,553
Messages
6,120,179
Members
448,948
Latest member
spamiki

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