Sue,
Sorry you lost me there.
"Once as Items..."
which line?
"Once as MAPIFolder."
Dim InputFolder As Outlook.MAPIFolder
Set InputFolder = olNS.Folders("Mailbox - Partners").Folders("Order
Notification")
The following in start up
Dim olMail As Items
Set olMail = InputFolder.Items
are related to
Private Sub InputFolder_ItemAdd(ByVal Item As Object)
Dim MessageText As String
Dim ItemReference As Integer
For ItemReference = olMail.Count To 1 Step -1
On Error Resume Next
MessageText = olMail(ItemReference).Body
If Err 0 Then MessageText = ""
On Error GoTo 0
..
..
olMail(ItemReference).UnRead = False
olMail(ItemReference).Move ProcessedFolder
..
..
--
Trefor
"Sue Mosher [MVP-Outlook]" wrote:
Putting your code in ThisOutlookSession was the right thing to do.
The problem is that you have duplicate declarations for InputFolder. Once as Items and once as MAPIFolder. You need to use two separate objects. It will be easiest to change the name of the MAPIFolder object. You will then need to add a statement to instantiate the Items object (InputFolder).
Also, there seems to be no purpose for the local olMail object in the Application_Startup procedure.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
"Trefor" wrote in message news
Sue,
Thankyou for the feedback. I have tried to change the code to match your
suggestion, but being a newbie to Outlook VBA I seem to be struggling.
I want to monitor a specific folder not just the Inbox. Below is my code,
can you let me know what I have done wrong. Also all my code is in
ThisOutlookSession, is this a problem?
Option Explicit
Private WithEvents InputFolder As Items
Private Sub Application_Startup()
Dim olNS As NameSpace
Dim InputFolder As Outlook.MAPIFolder
Dim ProcessedFolder As Outlook.MAPIFolder
Dim olMail As Items
Set olNS = Outlook.Application.GetNamespace("MAPI")
' Get reference to folder in user’s Mailbox for Input
Set InputFolder = olNS.Folders("Mailbox - Partners").Folders("Order
Notification")
' Get reference to folder in user’s Mailbox for Output (or Processed)
Set ProcessedFolder = olNS.Folders("Mailbox - Partners").Folders("Order
Notification Processed")
' Get reference to items in folder
Set olMail = InputFolder.Items
End Sub
Private Sub InputFolder_ItemAdd(ByVal Item As Object)
....stuff
End Sub
"Sue Mosher [MVP-Outlook]" wrote:
Correct: NewMailEx fires only for the user's own mail accounts, not for new mail delivered to other mailboxes opened as secondary mailboxes. The event to use for folders from other mailboxes would be MAPIFolder.Items.Add.
"Trefor" wrote in message ...
We have several users sharing a mailbox using the "Open these additional
mailboxes" option. Trouble is even if the VBA code is setup using this
configuration the procedure will not fire. If I create a new profile and
start outlook directly to this mailbox the sub routine fires just fine.
Does NewMailEx only work when you open the mailbox directly? Or am I doing
something wrong or is there a better way to do this?
Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
....stuff
end sub
--
Trefor