Hopner
11-10-2016, 07:56 AM
Hej guys,
I really need your help here!
My problem is that i often forget to look in the shared mailbox folder, and i know a lot of my colleagues do the same. I am trying to come up with a solution to this through VBA. I have tried the built in rule settings for Outlook, but with no luck.
So what i need is:
A macro that alerts me when an mail has been categorized as my responsiblity.
I have created the following with what i have found on the internet, but it only works for my own mailbox. I can't figure out how to do it on a shared mailbox.
Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
Dim olApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Set olApp = Outlook.Application
Set objNS = olApp.GetNamespace("MAPI")
' default local Inbox
Set Items = objNS.GetDefaultFolder(olFolderInbox).Items
End Sub
Private Sub Items_ItemAdd(ByVal Item As Object)
On Error GoTo ErrorHandler
Dim Msg As Outlook.MailItem
If TypeName(Item) = "MailItem" Then
Set Msg = Item
' ******************
MsgBox "Hej Mikkel"
' ******************
End If
ProgramExit:
Exit Sub
ErrorHandler:
MsgBox Err.Number & " - " & Err.Description
Resume ProgramExit
End Sub
Hopefully one of you guys can help me! I am pretty new with VBA in general, but i can see the potential in learning it.
I really need your help here!
My problem is that i often forget to look in the shared mailbox folder, and i know a lot of my colleagues do the same. I am trying to come up with a solution to this through VBA. I have tried the built in rule settings for Outlook, but with no luck.
So what i need is:
A macro that alerts me when an mail has been categorized as my responsiblity.
I have created the following with what i have found on the internet, but it only works for my own mailbox. I can't figure out how to do it on a shared mailbox.
Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
Dim olApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Set olApp = Outlook.Application
Set objNS = olApp.GetNamespace("MAPI")
' default local Inbox
Set Items = objNS.GetDefaultFolder(olFolderInbox).Items
End Sub
Private Sub Items_ItemAdd(ByVal Item As Object)
On Error GoTo ErrorHandler
Dim Msg As Outlook.MailItem
If TypeName(Item) = "MailItem" Then
Set Msg = Item
' ******************
MsgBox "Hej Mikkel"
' ******************
End If
ProgramExit:
Exit Sub
ErrorHandler:
MsgBox Err.Number & " - " & Err.Description
Resume ProgramExit
End Sub
Hopefully one of you guys can help me! I am pretty new with VBA in general, but i can see the potential in learning it.