none
Alternative to Office Automation for VC# 2010 express RRS feed

  • Question

  • I am looking for an alternative to Office Automation objects to obtain the MS Word Active Document path and file name, and the MS Excel path and filename for the active workbook.

    I have accomplished the extraction of the path and filename using .dotNet 4.0. However because of the need to pull focus and then return focus to the active window to get Word and Office instances to register in the Running Object Table, the active window flickers each time I poll the path and file name. Not only is this a visual irritant, its possible that some typed characters will not be recorded in the Office document.

    Any ideas for the alternative?

    Tuesday, January 25, 2011 6:55 PM

All replies

  • Hi Lou

    It might help us think about this if you could show us the code you're currently using to "poll" the path and file name...


    Cindy Meister, VSTO/Word MVP
    Wednesday, January 26, 2011 6:24 AM
    Moderator
  • Hi Lou

    It might help us think about this if you could show us the code you're currently using to "poll" the path and file name...


    Cindy Meister, VSTO/Word MVP


    My code is rather large. The essence of it is covered in http://support.microsoft.com/kb/316125/EN-US/. For the button, simply substitute a 1 sec. interval timer call, and omit the Process.Start call. The code "this.Activate();" pulls the focus from the Office App as it must do avoid a null value from the GetActiveObject() call.

    But this code is a detractor; I want an alternative approach, and not a workaround.

    Wednesday, January 26, 2011 10:45 PM
  • Hi Lou

    How about first checking the Processes, until it becomes available as a process? Then see if GetActiveObject works. If not, you can move the focus one single time, rather than have to keep attempting it?

    And/or use the Windows API to check for the the application window with a caption - if that's there the process should be loaded.


    Cindy Meister, VSTO/Word MVP
    Thursday, January 27, 2011 7:38 AM
    Moderator
  • Hi Lou

    How about first checking the Processes, until it becomes available as a process? Then see if GetActiveObject works. If not, you can move the focus one single time, rather than have to keep attempting it?

    And/or use the Windows API to check for the the application window with a caption - if that's there the process should be loaded.


    Cindy Meister, VSTO/Word MVP

    I don't attempt to use the Office object unless there is a process for the base object. This approach is a non-starter, as I have said and provided info for, in several posts now.

    The window caption does not have the full path name - try it.

    Thursday, January 27, 2011 4:19 PM
  • Hi Lou

    <<The window caption does not have the full path name >>

    I didn't imply that it did. I was suggesting that, once it's available the application is probably ready enough that it can be loaded into the ROT, so that you'd only have to do the deactivate the one single time. It's unlikely the user would start typing in the short amount of time it would take for your code to do the "flip" and the screen flicker would probably be seen as part of Word's loading process and not distract.

    I doubt there's any way you're going to find a way to register an application in the ROT otherwise. But if so, it would be at the Windows API level, which means you need to find a forum that supports that or contact paid support.


    Cindy Meister, VSTO/Word MVP
    Friday, January 28, 2011 7:48 AM
    Moderator
  • Hi Lou

    <<The window caption does not have the full path name >>

    I didn't imply that it did. I was suggesting that, once it's available the application is probably ready enough that it can be loaded into the ROT, so that you'd only have to do the deactivate the one single time. It's unlikely the user would start typing in the short amount of time it would take for your code to do the "flip" and the screen flicker would probably be seen as part of Word's loading process and not distract.

    I doubt there's any way you're going to find a way to register an application in the ROT otherwise. But if so, it would be at the Windows API level, which means you need to find a forum that supports that or contact paid support.


    Cindy Meister, VSTO/Word MVP

    Its OK. I have worked for months to get to this point and I should not have expected the same experience of anyone else.

    As for being here, I was sent here to ask this question again. I subsequently found out the helper was simply a blowhard.

    Lastly, I am fed up with fighting with the functionality of this web site. Everytime I come here I have to type everything twice and I lose edits 4 times over. Its simply too great a waste of time.

    Thank for for your efforts, but I am no longer interested.

    Friday, January 28, 2011 3:07 PM