Results 1 to 1 of 1

VBA Warning - Too Many Unread Emails in Specific shared mailbox

Threaded View

  1. #1
    Registered User
    Join Date
    05-11-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    3

    VBA Warning - Too Many Unread Emails in Specific shared mailbox

    An important gets sent into a shared mailbox, a requeast has been made to display a notification.My initial response to the customer was to setup an email rule.

    This wasn't sufficient, the user does not get a pop up alert that stays on the screen.After googling, you can configure a VBA script to pop up when there is more than X unread mail in an inbox.Unfortunately, I have not been able to get it to work for shared mailboxes, though it seems fairly possible.

    Private objInbox As Outlook.Folder
    Private WithEvents objItems As Outlook.Items
    Private lUnreadItemCount As Long
    
    Private Sub Application_Startup()
        Set objInbox = Application.Session.GetDefaultFolder(olFolderInbox)
        Set objItems = objInbox.Items
     
        lUnreadItemCount = 0
        Call CountUnreadEmails(objInbox, lUnreadItemCount)
     
        'If there are more than 10 unread emails
        If lUnreadItemCount > 10 Then
           MsgBox "Too many unread emails in Inbox!" & vbCr & "Please deal with them as soon as possible!", vbExclamation + vbOKOnly, "Check Unread Emails"
        End If
    End Sub
    
    Private Sub objItems_ItemAdd(ByVal Item As Object)
        Call CountUnreadEmails(objInbox, lUnreadItemCount)
     
        lUnreadItemCount = 0
        If lUnreadItemCount > 10 Then
           MsgBox "Too many unread emails!" & vbCr & "Please deal with them as soon as possible!", vbExclamation + vbOKOnly, "Check Unread Emails"
        End If
    End Sub
    
    Private Sub CountUnreadEmails(ByVal objFolder As Outlook.Folder, ByRef lCount As Long)
        Dim objUnreadItems As Outlook.Items
        Dim objSubfolder As Outlook.Folder
     
        Set objUnreadItems = objFolder.Items.Restrict("[Unread] = True")
        lCount = objUnreadItems.count + lCount
     
        'Process all subfolders under Inbox recursively
        If objFolder.Folders.count > 0 Then
           For Each objSubfolder In objFolder.Folders
               Call CountUnreadEmails(objSubfolder, lCount)
           Next
        End If
    End Sub
    I'm not very familiar with the VB syntax, I've never used it."

    To access a shared folder in another user's Exchange server mailbox, you need to use GetSharedDefaultFolder*to reference the mailbox"

    How do i add the following code in for shared mail?
    Last edited by squirrelz; 03-11-2019 at 08:46 AM. Reason: Moved from Excel Programming / VBA / Macros

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Save mails sent from shared mailbox in that shared mailbox's Sent folder
    By LordClick in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-22-2016, 03:30 PM
  2. Outlook 2010 VBA Code to open a link from an unread mail in a Shared Mailbox
    By MHamid in forum Outlook Programming / VBA / Macros
    Replies: 0
    Last Post: 10-31-2015, 03:46 PM
  3. Open newest unread email in shared mailbox
    By Aaron092 in forum Outlook Programming / VBA / Macros
    Replies: 1
    Last Post: 09-23-2014, 04:04 PM
  4. Excel Macro using VB Script to send emails from Common/Shared Mailbox
    By k.vijayendran in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-11-2014, 01:48 PM
  5. [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
  6. Need a VB script to read emails from mailbox
    By suprithr in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-06-2014, 12:55 AM
  7. Save emails sent on behalf of another mailbox in correct sent items folder
    By Domski in forum Outlook Programming / VBA / Macros
    Replies: 0
    Last Post: 04-06-2010, 12:53 PM

Tags for this Thread

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