0

I have a problem to find a simple way to cycle through all open instances of Excel and check if a specific workbook is already open.

I already know how to do it for only one instance:

  • GetObject
  • Check if Workbook is open

And i found a way to check how many instances are open / get the process id's of the open instances:

    Dim Counter As Int16 = 0
    Dim ExcelIDs() As Int16


    Dim ExcelApplications() As Process = Process.GetProcessesByName("EXCEL")

    For Each ExcelApplication As Process In ExcelApplications

        Counter += 1

        ReDim Preserve ExcelIDs(Counter)

        ExcelIDs(Counter) = ExcelApplication.Id

    Next

The Problem is that (to my knowledge) it's impossible to get a specific instance of excel with the GetObject command.

So what i would need is to find a way to either access specific instances ( eg. via the collected ID's) or any other way to loop through all the open instances.

Thanks

SanPalu
  • 13
  • 2
  • Read the notes here: [Get running instances of Excel with VB.NET](https://stackoverflow.com/a/51791847/7444103) – Jimi Aug 25 '19 at 19:32
  • As I understand you correctly the main goal you want to achieve is to check is the workbook is already open. I do not understand how looping through Excel instances will help you? The workbook might be open on the host that is not the same as this one which you running your code. IMO all you need is to try open the workbook in a try-catch block. –  Aug 26 '19 at 11:27
  • @Jimi, Thanks for your link, it did help me slightly, in the question to the answer you linked was a link to a working solution: [link](https://stackoverflow.com/questions/36265674/retrieve-all-workbook-names-during-more-than-one-excel-instances-are-running/36267576#36267576) – SanPalu Aug 27 '19 at 11:46
  • @DarkoMartinovic you're correct, i wouldn't catch it if the workbook was opened from somewhere else (i can catch that with a simple readonly check), what i try to catch is if the workbook is already open in some instance on the current host – SanPalu Aug 27 '19 at 11:46

0 Answers0