Get instance of Excel application with C# by Handle

后端 未结 3 1523
广开言路
广开言路 2020-11-28 09:16

I have a c# simple application that have to write some values in a excel ranges of a specific worksheet. I create an instance of Excel application if not exist, but if exist

3条回答
  •  日久生厌
    2020-11-28 10:00

    There might be more than one Excel instance running.

    GetActiveObject(...) looks in the Running Object Table (ROT) and would give you the last Excel instance that was opened - not necessarily the one corresponding with the window handle you have.

    You're looking for AccessibleObjectFromWindow(..). The Andrew Whitechapel post linked to in the other answer shows how to use this function.

    Another link - http://blogs.officezealot.com/whitechapel/archive/2005/04/10/4514.aspx.

提交回复
热议问题