1
votes

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!

1
Did you try anything else besides copy&pasting the code from that question?Tom K.
You should take a look at this for working with a shared mailbox slipstick.com/developer/code-samples/…Tom K.
Can you post the script you are trying to run?0m3r
@Tom yes I have tried some IF statements with GetNameSpace method but I think that's not a way to go.AkAntA
@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

1 Answers

1
votes

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