+ Reply to Thread
Results 1 to 2 of 2

Open newest unread email in shared mailbox

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-30-2014
    Location
    England
    MS-Off Ver
    MS Office 2010, 2007, 2003
    Posts
    149

    Open newest unread email in shared mailbox

    Hi all

    What I'm trying to achieve is when a new email comes into a shared inbox, a macro would open this email, run some code I've written which hands over to Excel and then repeat when another email comes in.
    If possible, not run when specific criteria are met (such as email has come from person@mail.com or subject is blank for example)

    This is the code I'm currently trying which doesn't seem to work:
    Sub OpenSharedEmail()
    Dim oRecip As Outlook.Recipient
    Dim oFolder As Outlook.MAPIFolder
    Dim oNS As Outlook.NameSpace
    Dim oSubFolder As Outlook.MAPIFolder
    
    Set oNS = Application.GetNamespace("MAPI")
    Set oRecip = oNS.CreateRecipient("TeamMail")
    oRecip.Resolve
        If oRecip.Resolved Then
            Set oFolder = oNS.GetSharedDefaultFolder(oRecip, olFolderInbox)
            Set oSubFolder = oFolder.Folders("Inbox")
    
                If Not (oSubFolder Is Nothing) Then
                MsgBox "Item 1 = " & oSubFolder.Items.item(1).Subject
                Else
                MsgBox "Could not get folder"
                End If
        End If
    End Sub
    Could someone point me in the right direction please?

    Thanks

    Aaron

  2. #2
    Forum Contributor
    Join Date
    08-27-2006
    Posts
    136

    Re: Open newest unread email in shared mailbox

    Fixed, but you do not want this code.

    Sub OpenSharedEmail()
    
    Dim oRecip As Outlook.Recipient
    Dim oFolder As Outlook.MAPIFolder
    Dim oNS As Outlook.Namespace
    
    Set oNS = Application.GetNamespace("MAPI")
    Set oRecip = oNS.CreateRecipient("TeamMail")
    
    oRecip.Resolve
    
    If oRecip.Resolved Then
        Set oFolder = oNS.GetSharedDefaultFolder(oRecip, olFolderInbox)
        MsgBox "Item 1 = " & oFolder.Items.Item(1).subject
    End If
    
    Set oNS = Nothing
    Set oRecip = Nothing
    
    End Sub
    Processing incoming mail is described here. http://www.outlookcode.com/article.aspx?id=62
    To mark "Solved" go to Thread Tools.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Sending email from a shared mailbox
    By badlydrunkboy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-02-2014, 10:12 AM
  2. [SOLVED] Show newl message envelop notification for all mailbox/shared mailbox added in outlook
    By Goku in forum Outlook Formatting & Functions
    Replies: 1
    Last Post: 07-04-2014, 01:23 PM
  3. Moving email from shared mailbox containing certain words
    By andysmith84 in forum Outlook Programming / VBA / Macros
    Replies: 0
    Last Post: 10-31-2013, 08:31 AM
  4. Reference shared Outlook mailbox
    By arneld in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-07-2012, 08:29 PM
  5. Lotus emailing through excel in Shared Group Mailbox
    By davegugg in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-08-2010, 03:50 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1