How to avoid Security PopUp in Outlook 2003

G

Greg

I am trying to write a couple of simple macros for Microsoft Outlook.
When I run the macros either manually or based on a rule when new email
is received I get a popup security warning that "A program is trying to
access e-mail addresses you have stored in Outlook "

I am running Microsoft Outlook 2003 on Windows 2000. I would like to
stop the popups from aplearing as it gets annoying to have to click ok
each time and I would like the first macro to run in the background on
selected emails on receipt. Is there a way to do this direct from VBA
without purchasing a 3rd party product?

Below are the macros I am trying to run

Macro #1: called by a rule when mail is received

Sub testMacro1(MyMail As MailItem)
Dim x As String
Dim strID As String

'------------------------------------------------------------------------
Dim muOlApp As Outlook.Application
'------------------------------------------------------------------------

Dim olNS As Outlook.NameSpace
Dim olMail As Outlook.MailItem
Dim mySubj, myMsg, mySender, myMsg2 As String
Dim rs As ADODB.Recordset
Dim fld As ADODB.Field
Dim sql As String

strID = MyMail.EntryID

(I have tried the following two lines and the line commented out below
them with the same results)
'------------------------------------------------------------------------
Set myOlApp = Application
Set olNS = myOlApp.GetNamespace("MAPI")
'------------------------------------------------------------------------
'Set olNS = Application.GetNamespace("MAPI")

Set olMail = olNS.GetItemFromID(strID)
mySubj = olMail.Subject
myMsg = olMail.Body (POPUP MESSAGE)
mySender = olMail.SenderEmailAddress (POPUP MESSAGE)

Set olMail = Nothing
Set olNS = Nothing

End Sub


Macro#2: Called manually from the toolbar
Sub addNewReq()
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim fld As ADODB.Field
Dim sql As String
Dim x As Long
Dim tst As String

mybody = ActiveInspector.CurrentItem.Body
mySubj = ActiveInspector.CurrentItem.Subject
mySender = ActiveInspector.CurrentItem.SenderEmailAddress
If InStr(1, mySender, "@") = 0 Then
x = InStrRev(mySender, "=")
mySender = Right$(mySender, Len(mySender) - x)
End If
end sub

I would appreciate any suggestions.
 
S

Sue Mosher [MVP-Outlook]

In Macro #1: Try changing olMail to msg or some other variable name. olMail is a member of one of Outlook's enumerations, so it may not work well as a variable name.

In Macro #2: ActiveInspector.CurrentItem.Body should properly be Application.ActiveInspector.CurrentItem.Body, but I suspect it makes no real difference.

Most important: Go to Help | About Microsoft Outlook and see what it says for "Security Mode." If it's not "User-controlled," then the VBA Application object is not "trusted" with regard to the Outlook "object model guard." You'll need to consider using one of the other approaches listed at http://www.outlookcode.com/d/sec.htm. Redemption is highly recommended.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top