1

I have tried to find answer to my question from all over the web. Since I don't have so much experience from outlook-vba I decided to ask here.

What I'm trying to do is to run a script when user opens a mail. Also I need to run this script only in shared mailboxes not in users own box.

I've used the code found in users @ZZA question # 21727768 but it has that little annoyance with creating a mail and replying to one also (it runs the script in these cases also). It is helpful but I haven't found a way to apply that code only to cases where user is opening a mail from shared mailbox.

Any help here?

Thanks!

braX
  • 11,506
  • 5
  • 20
  • 33
AkAntA
  • 13
  • 4
  • Did you try anything else besides copy&pasting the code from that question? – Tom K. Jul 06 '16 at 12:42
  • You should take a look at this for working with a shared mailbox http://www.slipstick.com/developer/code-samples/use-macro-assign-messages-shared-mailbox/ – Tom K. Jul 06 '16 at 12:46
  • Can you post the script you are trying to run? – 0m3r Jul 07 '16 at 05:08
  • @Tom yes I have tried some IF statements with GetNameSpace method but I think that's not a way to go. – AkAntA Jul 08 '16 at 04:32
  • @Om3r my script is at the moment basically the same as in the mentioned question but in the 'your code' part I just call other sub with the desired function. I get my script work in every mailbox but I want it to work only in shared ones. – AkAntA Jul 08 '16 at 04:36
  • This is what you are looking for: https://msdn.microsoft.com/us-en/library/office/ff868990.aspx – Tom K. Jul 08 '16 at 07:09

1 Answers1

1

Okay, I found an even easier way to do this (this is mostly code from the question linked to, in the OP)

Public WithEvents myItem As Outlook.MailItem
Public EventsDisable As Boolean



Private Sub Application_ItemLoad(ByVal Item As Object)
    If EventsDisable = True Then Exit Sub
    If Item.Class = olMail Then
        Set myItem = Item
    End If
End Sub


Private Sub myItem_Open(Cancel As Boolean)
    EventsDisable = True
    'this is the new part
    If myItem.Parent = "NAMEOFYOURSHAREDINBOX" Then
        'your code here
    End If
    EventsDisable = False
End Sub

Mostly credits to hstay

HTH

Community
  • 1
  • 1
Tom K.
  • 1,020
  • 1
  • 12
  • 28