Hi Guys,
I am trying to monitor a folder in our enterprise based on Outlook 2007. All i am trying to do is, as soon as a new email arrives. It plays a sound. And that's it.
There are couple of solutions that i have come across on the net. But most of them have taken this solution a bit too far. I am not very good with programming. But still gave it a try. This is the code that i have been able to put together so far.
Public Const SOUND_TO_PLAY = "C:\Windows\Media\Notify.wav"
Public Const SND_ASYNC = &H1
Public Declare Function sndPlaySound _
Lib "winmm.dll" Alias "sndPlaySoundA" _
(ByVal lpszSoundName As String, _
ByVal uFlags As Long) _
As Long
Option Explicit
Dim MailItemsCount As Integer
Private Fold1 As Outlook.MAPIFolder
Private WithEvents colItems1 As Outlook.Items
Private Sub Application_Startup()
'Insert the folder names here!
Set Fold1 = Application.GetNamespace("MAPI").Folders("Name of the folder to monitor").Folders("Inbox")
Set colItems1 = Fold1.Items
MailItemsCount = colItems1.Items.Count
If colItems1.Items.Count > MailItemsCount Then
sndPlaySound SOUND_TO_PLAY, SND_ASYNC
End If
End Sub
Private Sub Application_Quit()
'Clean Up
Set Fold1 = Nothing
Set colItems1 = Nothing
End Sub
Now these are the issues that i am facing.
I have placed this code in ThisOutlookSession, But when i try to compile it, It gives the error message saying: Compile Error : Constants, Fixed-length strings, arrays, user-defined types and Declare statement not allowed as Public members of object modules.
When i change declaration of constants to Private, the errors disappear. But, when, I run the the code nothing happens.
Second issue: Is, the below usage, the right logic to achieve what i am trying to achieve. I mean will it play the sound as soon as a new mail arrives in the shared mailbox?
Set colItems1 = Fold1.Items
MailItemsCount = colItems1.Items.Count
If colItems1.Items.Count > MailItemsCount Then
sndPlaySound SOUND_TO_PLAY, SND_ASYNC
End If
And the third thing is, the folder that i am trying access is an exchange based shared mailbox.
Is this the right way to access such a mailbox :
Set Fold1 = Application.GetNamespace("MAPI").Folders("Name of the folder to monitor").Folders("Inbox")
Your help in the matter is greatly appreciated.