Consulting

Results 1 to 2 of 2

Thread: How Use rules and VBA on shared accounts?

  1. #1

    How Use rules and VBA on shared accounts?

    I hope someone can help me with following problem.

    in my company we use shared accounts per project, which are accessible by all team members.
    All incoming emails (which are sent to the project account) are processed with server side rules, and automatically filed in the correct subfolders.
    This works quite well. However, some emails also end up in the shared account inbox by means of dragging and dropping (so not by actually sending the email to the account), and if this happens, the server side rules do not run. I tried to work around this by dragging and dropping the emails in a subfolder, from which they can be moved to the parent inbox with a button macro (which works perfectly well), but this apparently also does not trigger the rules when the moved emails 'arrive' in the inbox.
    I have full permissions and also have the user and password for the shared account, but I would like to avoid having to change between profiles all the time, as this would lead to error 'I'm not the only one who would need to switch constantly, so this will surely introduce errors at some point).

    So basically, my question is, how can I fire a rule on the inbox of a shared account, without being logged in, if the email is dragged and dropped into the folder rather than actually being sent?

    Any help would be very welcome.

  2. #2
    VBAX Mentor skatonni's Avatar
    Joined
    Jun 2006
    Posts
    347
    Location
    Add the shared account Mailbox to your own profile.

    See itemAdd information here http://www.outlookcode.com/article.aspx?id=62

    See Run Rules Now sample here http://www.vboffice.net/en/developers/run-rules-now

    Option Explicit
    
    ' Should look like this untested code
    ' In ThisOutlookSession
    Private WithEvents olSharedMailboxInboxItems As Items
    
    Private Sub Application_Startup()
    Dim objNS As Namespace
    ' This code is applicable where the shared mailbox is added to your profile
    Set objNS = Application.GetNamespace("MAPI")
    On Error GoTo SharedMailboxNotInProfile
    Set olSharedMailboxInboxItems = objNS.Folders("SharedMailbox Name").Folders("Inbox").Items
    On Error GoTo 0
    Debug.Print vbCr & "Adding items to the - Shared Mailbox Inbox will trigger SharedMailboxInboxItems_ItemAdd"
    GoTo ExitRoutine
    SharedMailboxNotInProfile:
        Debug.Print "olSharedMailboxInboxItems_ItemAdd works if SharedMailbox is in the profile."
    ExitRoutine:
        Set objNS = Nothing
    End Sub
    
    Private Sub SharedMailboxInboxItems_ItemAdd(ByVal Item As Object)
              
        If TypeOf Item Is MailItem Then
    
            MsgBox "Item added to SharedMailboxInbox."
    
            ' Rules apply to the folder not the added message
            ' In the rule you will likely want to move the item so it is not processed again
            
        End If
        
    End Sub
    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.

Posting Permissions

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