Excel VBA code and Outlook Programmatic Access warning

1

Since about last Friday one of my Excel macros that generates an email has been getting this warning:

Microsoft Outlook: A program is trying to access e-mail address information stored in Outlook. If this is unexpected, click Deny and verify your antivirus software is up-to-date. For more information about e-mail safety and how you might be able to avoid getting this warning, click Help. Allow access for 1 minute. Allow, Deny, Help

enter image description here

I've narrowed it down to lines that concatenate strings to the mail object's HTMLBody property, like so:

.HTMLBody = .HTMLBody & "<br>" & "<br>"

However lines that only assign values do not trigger the warning:

.HTMLBody = "<BODY style=font-size:11pt;font-family:Calibri><br>"

Does anyone know what caused this change in behavior?

Ampersand

Posted 2016-06-28T20:51:11.763

Reputation: 705

2Reading the HTMLBody property is considered a security risk, as malicious code could read your inbox. You might want to look at 3rd party products like Outlook Redemption. – ThunderFrame – 2016-06-28T20:55:35.313

That makes sense. I've found a workaround by composing the body in a string and writing to HTMLBody only once at the end, which looks like a better way all around. If you post what you have as the answer I will set it as the solution. – Ampersand – 2016-06-28T21:12:42.817

Answers

1

Reading the HTMLBody property is considered a security risk, as malicious code could read your inbox. You might want to look at 3rd party products like Outlook Redemption.

As you rightly determined, setting the property with a pre-constructed HTML string will avoid the need to read the HTMLBody property, and it will likely be more efficient too.

ThunderFrame

Posted 2016-06-28T20:51:11.763

Reputation: 1 015