T
typingcat
The following is a very simple VBScript to popup a massage box when new
mails arrived to the inbox.
========================================================
Dim Inbox As Folder
Dim InboxMails As Items
Private Sub Application_Startup()
Set Inbox = GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
Set InboxMails = Inbox.Items
End Sub
Private Sub InboxMails_ItemAdd(ByVal Item As Object)
MsgBox "Item ADD"
End Sub
Private Sub InboxMails_ItemChange(Item As Object)
MsgBox "item change"
End Sub
========================================================
I also added this to check whether InboxMails is properly set;
Private Sub Application_FolderContextMenuDisplay(ByVal CommandBar As
Office.CommandBar, ByVal Folder As MAPIFolder)
'To test InboxMails is properly set.
Set Inbox = GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
Set InboxMails = Inbox.Items
MsgBox "There " & InboxMails.Count & " mails in the inbox"
End Sub
When I right cliked a folder the massage box worked as I expected. Thus
I'm sure
that the InboxMails is set to an Items object. But InboxMails_ItemAdd
nor
InboxMails_ItemChange worked. I tried many times but in vein. What's
wrong
with my code? Please help me. Thank you.
mails arrived to the inbox.
========================================================
Dim Inbox As Folder
Dim InboxMails As Items
Private Sub Application_Startup()
Set Inbox = GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
Set InboxMails = Inbox.Items
End Sub
Private Sub InboxMails_ItemAdd(ByVal Item As Object)
MsgBox "Item ADD"
End Sub
Private Sub InboxMails_ItemChange(Item As Object)
MsgBox "item change"
End Sub
========================================================
I also added this to check whether InboxMails is properly set;
Private Sub Application_FolderContextMenuDisplay(ByVal CommandBar As
Office.CommandBar, ByVal Folder As MAPIFolder)
'To test InboxMails is properly set.
Set Inbox = GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
Set InboxMails = Inbox.Items
MsgBox "There " & InboxMails.Count & " mails in the inbox"
End Sub
When I right cliked a folder the massage box worked as I expected. Thus
I'm sure
that the InboxMails is set to an Items object. But InboxMails_ItemAdd
nor
InboxMails_ItemChange worked. I tried many times but in vein. What's
wrong
with my code? Please help me. Thank you.