Get specific excel instance/process

Y

Yaris Sabzposh

Hi,

I have several excel processes running, and I would like to have an option
to choose from that list. I am able to get the list of processes and I can
choose which process I want, but the problem starts when we try to
cast/convert that process into an excel object.

I can use the following:

xlApp = (Excel.Application)
(Microsoft.VisualBasic.Interaction.GetObject(null, "Excel.Application"));


but that'll give me the first instance of excel, not the 3rd or 4th or nth
instance that I would like to get a handle on.

Is there a way of doing that in C#? I know in VB we can write:

Set xlApp = GetObject("book2").Application

and it'll get us the excel workbook/process with the name "book2".

I would really appreciate if someone can help me out here.

Thanks.

--Yaris

PS: Sorry if I'm posting in the place.
 
B

bourgui

Hi Yaris,

I'm not sure if this is what you are looking for, but you could get
any workbook by looping through the open workbooks like that:

Code:
Dim oXLApp As Object
Dim oWkBk As Object
Dim iCtr As Integer

On Error GoTo NotRunning
Set oXLApp = GetObject(, "Excel.Application")
For iCtr = 1 To oXLApp.WorkBooks.count
If oXLApp.WorkBooks(iCtr).Name = "WkbkName.xls" Then
Set oWkBk = oXLApp.WorkBooks(iCtr)
End If
Next iCtr
[CODE]


Or is there something that I'm missing?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top