none
Application.ActiveWindow throws InvalidCastException RRS feed

  • Question

  • I'm using Outlook 2013:  
    Project Type:  C# COM Add_in

    RECREATE STEPS
    From Explorer do CTRL+SHIFT+F to bring up the "Advanced Find" window
    Double click on one of the documents to open it.

    At this point I need to check the Document object of the Message Item. For this I need to know if the Window is an Inspector window or an Explorer Window  (e.g.  Inspector.WordEditor, or Explorer.ActiveInlineResponseWordEditor)

    However, since the ActiveWindow is NEITHER an Inspector nor an Explorer an Exception is thrown.  I thought I would simply get a NULL value back.


    Is there some value of the MailItem object I can inspect so that I don't even attempt to check for the ActiveWindow in the first place if the MailItem is "Not Ready".


    Tuesday, August 1, 2017 7:01 PM

Answers

  • So if you catch the exception using try/catch, that would be your clue that the active window is neither Explorer nor Inspector.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    • Marked as answer by GermanEZI Tuesday, August 1, 2017 11:13 PM
    Tuesday, August 1, 2017 9:34 PM

All replies

  • So if you catch the exception using try/catch, that would be your clue that the active window is neither Explorer nor Inspector.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    • Marked as answer by GermanEZI Tuesday, August 1, 2017 11:13 PM
    Tuesday, August 1, 2017 9:34 PM
  • Yes, that's what I'm doing.   I'm catching the exception.  

    I just thought I would be getting a Null back.  Perhaps the Nothing return value is just for VBA .



    Tuesday, August 1, 2017 11:13 PM
  • The behavior would be the same in VBA and .Net - Outlook does not know (or care) which language is calling its methods.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Tuesday, August 1, 2017 11:41 PM