AOB
Well-known Member
- Joined
- Dec 15, 2010
- Messages
- 660
- Office Version
- 365
- 2016
- 2013
- Platform
- Windows
Hi everybody,
I have some script to connect to an Outlook mailbox / folder and read the information for each mail item which a) contains a pdf attachment and b) was sent within a date range (defined by two date-picker controls on the form) into an array, to subsequently populate a combobox on a user form in Excel.
But when running, I get prompted in Outlook :
So the user would have to manually allow access (for 1-10 minutes) in order for the script to run. While I can certainly see the reasoning behind this prompt, I'd like to bypass it / prevent it from stalling the process (also, not sure how to apply error-handling in the event that the user were to click 'Deny')
Found an interesting article here which suggests using the Application object (as it is trusted in Outlook VBA and therefore should bypass the security prompt) but am still getting the prompt.
Here's my code :
It's the line in red where the security prompt kicks in.
Does anybody know any way of restructuring this so that Outlook does not flag a security concern?
Thanks in advance!
AOB
I have some script to connect to an Outlook mailbox / folder and read the information for each mail item which a) contains a pdf attachment and b) was sent within a date range (defined by two date-picker controls on the form) into an array, to subsequently populate a combobox on a user form in Excel.
But when running, I get prompted in 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
So the user would have to manually allow access (for 1-10 minutes) in order for the script to run. While I can certainly see the reasoning behind this prompt, I'd like to bypass it / prevent it from stalling the process (also, not sure how to apply error-handling in the event that the user were to click 'Deny')
Found an interesting article here which suggests using the Application object (as it is trusted in Outlook VBA and therefore should bypass the security prompt) but am still getting the prompt.
Here's my code :
Code:
Dim olApp As Outlook.Application
Dim objNameSpace As Outlook.Namespace
Dim objFolder As Outlook.MAPIFolder
Dim objItem As MailItem
Dim strID As String
Dim objMail As MailItem
Dim att As Variant
Dim arTempEMails() As String
Set olApp = CreateObject("Outlook.Application")
Set objNameSpace = olApp.GetNamespace("MAPI")
ReDim arTempEMails(1 To 5, 1 To 1)
lgNoOfEmails = 0
For Each objItem In objFolder.Items
[INDENT]If objItem.SentOn >= Me.dtStartDate.Value And _
objItem.SentOn < (Me.dtEndDate.Value + 1) Then
[/INDENT]
[INDENT=2]If objItem.Attachments.Count > 0 Then
[/INDENT]
[INDENT=3]For Each att In objItem.Attachments
[/INDENT]
[INDENT=4]If Right(att.DisplayName, 4) = ".pdf" Then
[/INDENT]
[INDENT=5]lgNoOfEmails = lgNoOfEmails + 1
ReDim Preserve arTempEMails(1 To 5, 1 To lgNoOfEmails)
strID = objItem.EntryID
Set objMail = objNameSpace.GetItemFromID(strID)
arTempEMails(1, lgNoOfEmails) = objMail.EntryID
[COLOR=#ff0000]arTempEMails(2, lgNoOfEmails) = objMail.SenderName
[/COLOR]arTempEMails(3, lgNoOfEmails) = objMail.Subject
arTempEMails(4, lgNoOfEmails) = Format(objMail.SentOn, "dd-mmm-yyyy hh:mm:ss")
arTempEMails(5, lgNoOfEmails) = att.DisplayName
GoTo NextEMail[/INDENT]
[INDENT=4]
End If[/INDENT]
[INDENT=3]
Next att[/INDENT]
[INDENT=2]
End If
[/INDENT]
[INDENT]ElseIf objItem.SentOn < Me.dtStartDate.Value Then[/INDENT]
[INDENT=2]
Exit For[/INDENT]
[INDENT]
End If
NextEMail:
[/INDENT]
Next objItem
It's the line in red where the security prompt kicks in.
Does anybody know any way of restructuring this so that Outlook does not flag a security concern?
Thanks in advance!
AOB