none
Prevent (or intercept) Opening of mail / document items RRS feed

  • Question

  • Is it possible to intercept/override the default behaviour of Outlook when opening a mail or document item (either by double clicking or pressing enter)? Or, if there's no event to intercept, is there some way to suppress it happening at all?

    I've looked through the various events like BeforeAttachmentPreview etc. but I couldn't see a way to distinguish between the attachment being opened in a separate program and the attachment simply being previewed in the preview pane.

    I'm open to any ideas about how to achieve this, but please let me know if I'm going down a dead-end with this idea!

    Cheers,

    Chris


    • Edited by Chris McA Wednesday, April 24, 2013 2:45 PM
    Wednesday, April 24, 2013 2:36 PM

Answers

  • I did some testing of this and while a Word doc dropped into a folder is an Outlook.DocumentItem, it is not firing any of the usual Outlook events for NewInspector() or item.Open(). It does have a Class == olDocument.
     
    I don't see any way of trapping what you want from inside Outlook. About the only thing I can think of, and it's a hack, is to have a Word addin that prevents the item from opening. But you'd have to be able to identify the item. And I don't see any cancel parameter in either Document.Open() or Application.DocumentOpen() or any other way of canceling opening the document. About all you can do it appears is to force the window closed when it does open.
     
    All in all, it doesn't look like you'd be able to do what you want without resorting to Win32 API hacks of finding a Word window and checking caption to see if it matches the caption of a selected DocumentItem. Even there I see possible ways to avoid havng the document becoming selected.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Chris McA" <=?utf-8?B?Q2hyaXMgTWNB?=> wrote in message news:7af483a5-b2d1-40b9-8e95-a03b196b28c4...

    Sorry I should have been clearer - I was referring to opening Word documents from within Outlook (i.e. documents which have been dragged and dropped into folders).

    By "open in its native program", I was referring to when you double click (or press enter) on a document item within Outlook, it is opened externally (so double clicking on a word document will open Word etc.).

    My understanding is that Outlook writes the file out to the temporary directory, begins monitoring the file handle of the process which opened the file, and once it's released it updates the document item in the folder with the contents of the file on disk.

    What I'm interested in is working out if there's a way to circumvent this behaviour by preventing Outlook from ever opening the item in the first place.


    Ken Slovak MVP - Outlook
    • Marked as answer by Chris McA Friday, April 26, 2013 2:04 PM
    Thursday, April 25, 2013 2:37 PM
    Moderator

All replies

  • Which do you want, handling attachments or opening items, or was this a question about both?
     
    For attachments, you have various events for different scenarios. Aside from BeforeAttachmentPreview() look at BeforeAttachmentRead() and BeforeAttachmentWriteToTempFile().
     
    You can handle the NewInspector() event to know when an item is being opened and what type of item it is. That event does not have a cancel argument. If you handle the Open() event for the Inspector.CurrentItem object that does have a cancel argument that allows you to prevent the item from opening and where you can close the Inspector. Expect a brief flash on the screen though.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Chris McA" <=?utf-8?B?Q2hyaXMgTWNB?=> wrote in message news:52ca6593-7cf4-49ce-a90c-bec07c8b3aae...

    Is it possible to intercept/override the default behaviour of Outlook when opening a mail or document item (either by double clicking or pressing enter)? Or, if there's no event to intercept, is there some way to suppress it happening at all?

    I've looked through the various events like BeforeAttachmentPreview etc. but I couldn't see a way to distinguish between the attachment being opened in a separate program and the attachment simply being previewed in the preview pane.

    I'm open to any ideas about how to achieve this, but please let me know if I'm going down a dead-end with this idea!

    Cheers,

    Chris



    Ken Slovak MVP - Outlook
    Wednesday, April 24, 2013 2:58 PM
    Moderator
  • Hi Ken,

    Thanks for the reply.

    Does the Open event on Inspector.CurrentItem fire whenever the item is simply selected, or does it fire when you actually try to open the item in its native program (be that Outlook itself or e.g. MS Word)?

    Chris

    Wednesday, April 24, 2013 3:51 PM
  • You would need to handle Open() in Outlook code. I'm not sure where Word comes into this in an Outlook forum.
     

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Chris McA" <=?utf-8?B?Q2hyaXMgTWNB?=> wrote in message news:fcbeaad7-bab0-454e-9f4d-6b1b1b8dcf1b...

    Hi Ken,

    Thanks for the reply.

    Does the Open event on Inspector.CurrentItem fire whenever the item is simply selected, or does it fire when you actually try to open the item in its native program (be that Outlook itself or e.g. MS Word)?

    Chris


    Ken Slovak MVP - Outlook
    Wednesday, April 24, 2013 4:18 PM
    Moderator
  • Sorry I should have been clearer - I was referring to opening Word documents from within Outlook (i.e. documents which have been dragged and dropped into folders).

    By "open in its native program", I was referring to when you double click (or press enter) on a document item within Outlook, it is opened externally (so double clicking on a word document will open Word etc.).

    My understanding is that Outlook writes the file out to the temporary directory, begins monitoring the file handle of the process which opened the file, and once it's released it updates the document item in the folder with the contents of the file on disk.

    What I'm interested in is working out if there's a way to circumvent this behaviour by preventing Outlook from ever opening the item in the first place.

    Wednesday, April 24, 2013 8:17 PM
  • I did some testing of this and while a Word doc dropped into a folder is an Outlook.DocumentItem, it is not firing any of the usual Outlook events for NewInspector() or item.Open(). It does have a Class == olDocument.
     
    I don't see any way of trapping what you want from inside Outlook. About the only thing I can think of, and it's a hack, is to have a Word addin that prevents the item from opening. But you'd have to be able to identify the item. And I don't see any cancel parameter in either Document.Open() or Application.DocumentOpen() or any other way of canceling opening the document. About all you can do it appears is to force the window closed when it does open.
     
    All in all, it doesn't look like you'd be able to do what you want without resorting to Win32 API hacks of finding a Word window and checking caption to see if it matches the caption of a selected DocumentItem. Even there I see possible ways to avoid havng the document becoming selected.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Chris McA" <=?utf-8?B?Q2hyaXMgTWNB?=> wrote in message news:7af483a5-b2d1-40b9-8e95-a03b196b28c4...

    Sorry I should have been clearer - I was referring to opening Word documents from within Outlook (i.e. documents which have been dragged and dropped into folders).

    By "open in its native program", I was referring to when you double click (or press enter) on a document item within Outlook, it is opened externally (so double clicking on a word document will open Word etc.).

    My understanding is that Outlook writes the file out to the temporary directory, begins monitoring the file handle of the process which opened the file, and once it's released it updates the document item in the folder with the contents of the file on disk.

    What I'm interested in is working out if there's a way to circumvent this behaviour by preventing Outlook from ever opening the item in the first place.


    Ken Slovak MVP - Outlook
    • Marked as answer by Chris McA Friday, April 26, 2013 2:04 PM
    Thursday, April 25, 2013 2:37 PM
    Moderator
  • Hm, that's a shame - but thank you for taking the time to investigate, I appreciate the effort!

    Regards,

    Chris

    Friday, April 26, 2013 2:04 PM