VBA Assistance Excel 365

Raiders

New Member
Joined
Nov 21, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi,

I am looking for assistance with some VBA code that I have posted an extract of below.

I have been using this code for some time with no issues, however, my organisation recently updated from Excel 2010 to Excel 365 and the code that I have been running now has a "Run-time error '287': Application-defined or object-defined error" occurring at the line:
.HTMLBody = strbody & "<br>" & .HTMLBody

I can remove that line from the code and it presents the email with the standard Outlook Signature, but the text in the email body will be removed.

Could anyone please advise if they can see what needs to be updated (or changed) in the below code to make it work.

Thanks

VBA Code:
Sub EmailReport()

Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String

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

strbody = "<H3></H3>" & _
            "<br>" & "<br>" & _
        "Please see attached Report." & "<br>" & "<br>" & _
        "" & "<br>" & "<br>" & _
        "Regards,"

With OutMail
.SentOnBehalfOfName = "123@abc.com"
.Display
.To = ""
.CC = ""
.BCC = ""
.Subject = ""
.HTMLBody = strbody & "<br>" & .HTMLBody
.Display
End With

On Error GoTo 0

With Application
.EnableEvents = 1
.Calculation = xlCalculationAutomatic
End With

OutMail.Display
Set OutMail = Nothing
Set OutApp = Nothing

End Sub
 
Last edited by a moderator:

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Runs fine for me in 365. Make sure in Tools - References you have the below references checked.
Other than that get your IT to check your security policies, in particular

HKEY_CURRENT_USER\Software\Policies\Microsoft\office\16.0\outlook\security\promptoomsend

and make sure it is not set to 0

1637556239272.png
 
Upvote 0
Runs fine for me in 365. Make sure in Tools - References you have the below references checked.
Other than that get your IT to check your security policies, in particular

HKEY_CURRENT_USER\Software\Policies\Microsoft\office\16.0\outlook\security\promptoomsend

and make sure it is not set to 0

View attachment 51783
Thanks Mark858. I'll investigate that option with my IT department. I checked the other Tools - References and all was ok there.

I'll let you know the outcome once I have gone through the IT department.
 
Upvote 0

Forum statistics

Threads
1,214,950
Messages
6,122,428
Members
449,083
Latest member
Ava19

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