Consulting

Results 1 to 3 of 3

Thread: Shared mailbox

  1. #1
    VBAX Newbie
    Joined
    Nov 2016
    Posts
    4
    Location

    Shared mailbox

    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.

  2. #2
    VBAX Mentor skatonni's Avatar
    Joined
    Jun 2006
    Posts
    347
    Location
    Instead of GetDefaultFolder(olFolderInbox), point to it like this.

    Set Items = objNS.Folders("shared mailbox name as a string").Folders("Inbox").Items
    To debug, mouse-click anywhere in the code. Press F8 repeatedly to step through the code. http://www.cpearson.com/excel/DebuggingVBA.aspx

    If your problem has been solved in your thread, mark the thread "Solved" by going to the "Thread Tools" dropdown at the top of the thread. You might also consider rating the thread by going to the "Rate Thread" dropdown.

  3. #3
    VBAX Newbie
    Joined
    Nov 2016
    Posts
    4
    Location
    Thanks for the reply, but it says that no object was found?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •