Link to home
Start Free TrialLog in
Avatar of upobDaPlaya
upobDaPlaya

asked on

Excel VBA that scrapes bod from email triggers Outlook Security Message "A program is trying to access e-mail addresses"

Excel VBA
MS Outlook 2010
VBA runs code to grab the body of the Outlook email

Early binding does not create an issue so far...
However,  late binding triggers an Outlook Pop Up Message:OutLook Security Message programatically : A program is trying to access e-mail addresses ?
Early Binding does not appear to create an issue ?  Note I am not allowed to change my Outlook settings - The Programatical Access options are greyed out.  Thus this is not an option for me to fix the late binding issue by changing my Outlook settings or loading 3rd party software.

Shouldn't I get a security message for both late binding and early binding ?  

Also why does the message indicate I am trying to access email addresses when all I am trying to do is scrape the body of the email...Also odd is I have no issue (no security messages) within Excel VBA saving off attachments from my Outlook Folders.  Its only when trying to scrape the body of the email a security message displays.


Sub Extract_Body_Subject_From_Mails()

Dim oNS As Outlook.NameSpace
Dim oFld As Outlook.Folder
Dim oMails As Outlook.Items
Dim oMailItem As Outlook.MailItem
Dim oProp As Outlook.PropertyPage

Dim sSubject As String
Dim sBody

On Error GoTo Err_OL

Set oNS = Application.GetNamespace("MAPI")
Set oFld = oNS.GetDefaultFolder(olFolderInbox)
Set oMails = oFld.Items

For Each oMailItem In oMails
sBody = oMailItem.Body
sSubject = oMailItem.Subject 'This property corresponds to the MAPI property PR_SUBJECT. The Subject property is the default property for Outlook items.
Next

Exit Sub
Err_OL:
If Err <> 0 Then
MsgBox Err.Number & " - " & Err.Description
Err.Clear
Resume Next
End If
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of upobDaPlaya
upobDaPlaya

ASKER

Thanks !
You’re welcome and I’m glad I was able to help.

If you expand the “Full Biography” section of my profile you’ll find links to some articles I’ve written that may interest you.

Marty - Microsoft MVP 2009 to 2017
              Experts Exchange Most Valuable Expert (MVE) 2015, 2017
              Experts Exchange Top Expert Visual Basic Classic 2012 to 2018
              Experts Exchange Top Expert VBA 2018
              Experts Exchange Distinguished Expert in Excel 2018