none
Getting a specific workbook object from all running instances of excel RRS feed

  • Question

  • Hi all,
    I've used the following code to get the active workbook of an excel instance.

    xlsApp = (Microsoft.Office.Interop.Excel.
    Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
    WorkBook = xlsApp.Workbooks[workBookName];

     

     

    what if I have a multiple instances of Excel.exe on Task Manager
    and I want to search for a specific workbook.
    for example:
    first instance of Excel contains workbooks: "Book1", Book2", "Book3"
    second instance of Excel contains workbooks: "Book4", Book5", "Book6"

    from my code I'll capture the first or the second instance randomally. I want to be able to loop of all worbooks in all existing instances

    Thursday, October 1, 2009 1:51 PM

Answers

  • This is a limitation in COM, finding a workaround isn't going to be a lot of fun.  Check this KB article for code that demonstrates iterating the ROT.

    Hans Passant.
    • Marked as answer by eryang Wednesday, October 7, 2009 2:15 AM
    Friday, October 2, 2009 1:21 PM
    Moderator