StartDownloadsServiceSamplesWorkshopsContact DeutschEnglish
 
Samples
General
Outlook®
 
Awarded by
Microsoft since 2005:
mvp logo
VBOffice Info
Visitors1827854
Impressions6857209
Links
Imprint
Privacy Policy
Contact
Security modell: Access blocked properties
Author: Michael BauerHomepage
Date: 18.12.2010Accessed: 12304
  
Description

Since Outlook 2000 SP3 (optional) or Outlook XP respectively, some properties are blocked for security reasons, for instance the sender address of e-mails.

Since Outlook 2003 even blocked properties can be read in VBA without raising the security prompt by using the instrinsic Application object. That means, in VBA there's already a variable called Application, which should be used. You don't need to create this variable. And there's the rub, even with the official VBA help file: Examples often use the functions GetObject or CreateObject to retrieve a variable for the Application object.

The following examples demonstrate the difference. In order to test the examples, there must be at least one email stored in the inbox.

Example_1 shows how it does not work. Instead of simply using the intrinsic Application object, the variable olApp is set to the Application object by using the GetObject function. The effect is, the security prompt is raised as soon as you want to access the blocked SenderEmailAddress property.

Example_2 shows how to avoid the security alert: The variable olApp is directly set to the Application object without using the GetObject function.

In Outlook 2003 you should also pay attention to this: If you create a Run-a-Script rule, the rule wizzard will pass a blocked MailItem to your script. Since Outlook 2007 this doesn't happen any more.

In order to turn this blocked variable into a non-blocked one, you must apply the same principle: The variable must be derived from the intrinsic Application object.

Example_3 demonstrates how it does not work (Outlook 2003 only).

Example_4 shows how to derive the variable by using the instrinsic Application object. This way accessing the SenderEmailAddress is not blocked.

Public Sub Example_1()
  Dim olApp As Outlook.Application
  Dim Inbox As Outlook.MAPIFolder
  Dim Mail As Outlook.MailItem

  Set olApp = GetObject(, "Outlook.Application")

  Set Inbox = olApp.Session.GetDefaultFolder(olFolderInbox)
  Set Mail = Inbox.Items(1)
  MsgBox Mail.SenderEmailAddress
End Sub

Public Sub Example_2()
  Dim olApp As Outlook.Application
  Dim Inbox As Outlook.MAPIFolder
  Dim Mail As Outlook.MailItem

  Set olApp = Application

  Set Inbox = olApp.Session.GetDefaultFolder(olFolderInbox)
  Set Mail = Inbox.Items(1)
  MsgBox Mail.SenderEmailAddress
End Sub

Public Sub Example_3(NewMail As Outlook.MailItem)
  MsgBox NewMail.SenderEmailAddress
End Sub

Public Sub Example_4(NewMail As Outlook.MailItem)
  Dim Session As Outlook.NameSpace
  Dim EntryID$, StoreID$
  Dim Mail As Outlook.MailItem

  EntryID = NewMail.EntryID
  StoreID = NewMail.Parent.StoreID

  Set Session = Application.Session
  Set Mail = Session.GetItemFromID(EntryID, StoreID)

  MsgBox Mail.SenderEmailAddress
End Sub
 
 

ReplyAll alerts you before unintentionally replying all, or if you are a confidential BCC recipient of the ... [more]

 

Access the master category list in the blink of an eye, share your categories in a network, get a reminder service, and ... [more]

 

SAM automatically sets the sender, signature, and folder for sent items, for instance based on the recipient ... [more]

 

OLKeeper reliably prevents users from closing their Outlook window and thus possibly missing reminders or ... [more]