LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I get a refnum to multiple open excel instances?

I'm using ActiveX to control interface to Excel2007 from my application (Labview8.5). Unfortunately, if I call Open Automation multiple times with 'create a new instance' set to false, a reference to the same instance of Excel is returned. I would like to get a reference to each open Excel instance. I can use the vi 'Get Task List' then use the vi 'Quit Application' to exit. Problem is if there are changes to be saved then Excel does not exit.

I know I can get all the processes with .NET, but am unsure how to save and exit using .NET.

Thanks in advance for any help.

 

0 Kudos
Message 1 of 10
(4,028 Views)

Hi Rickie!

I looked into how you might save and exit programs using .NET, and was able to find this information on saving files using .NET and I was also able to find this information on manipulating files using .NET commands.

 

As for ActiveX, you will need to see if you can assign GUID values to each instance of Excel that you have opened.  In some instances the GUID value assigned to multiple instances of a program will be the same, so this may not be possible.  I would look more into this and get back to us so we can keep working with you on this.

0 Kudos
Message 2 of 10
(4,009 Views)

Thanks for the reply.

Those links are not really what I'm after.

I think the only way to do this is:

 

LOOP

Open Automation to excel

IF Excel has workbooks Open THEN

Save all workbooks

Quit excel

CONTINUE

ELSE Exit the loop with the new instance

ENDLOOP

 

The downside to this is it closes every instance of EXCEL instead of targeting one instance with the workbook I am concerned with.

 

 

0 Kudos
Message 3 of 10
(4,001 Views)

@Ben-N wrote:

Hi Rickie!

I looked into how you might save and exit programs using .NET, and was able to find this information on saving files using .NET and I was also able to find this information on manipulating files using .NET commands.


You can't save Excel files that way.

 

As for the question: I don't understand why you are opening multiple instances of Excel. Wouldn't it be easier to have one Excel process running and simply open multiple workbooks?

0 Kudos
Message 4 of 10
(3,988 Views)

I don't open multiple instances of Excel within my program.

However, that does not preclude them from being open by users.

Example:

Two instances of Excel are already open by a user who is viewing data.

Now my program needs to open a workbook that the user has left open. There's no guarantee that only one instance is open.

If I open an automation and get the instance to the the app that doesn't contain my workbook, then I can't see the workbooks in the other app instance.

Therefore when I try to open the workbook it will be readonly and of no use to me.

This is for error recovery since the program runs all night unattended. Typical program runtime is 20 hours, so the program can't stall for any reason.

Hopefully, this explains why better.

 

0 Kudos
Message 5 of 10
(3,983 Views)

One thing you might want to check is see if Excel is in Task Manager. I don't know if this can be done in LabVIEW, but worth investigating.

 

or

convert to LabVIEW http://xldennis.wordpress.com/2007/11/25/access-running-instances-of-excel-in-vb/

 

 

0 Kudos
Message 6 of 10
(3,968 Views)

Hi Rickie,

You might refer to the News_Archive VI from the link below where you can see the activex references for excel, as well as the invoke methods you are looking for. You just need to check for proper invoke property, and you would be able to do what you want.

Still, I am not sure why you want to approach this way in your application

 

Link: Click Here

Download the last (task3) zip file from above link

 

Hope this helps

-FraggerFox!
Certified LabVIEW Architect, Certified TestStand Developer
"What you think today is what you live tomorrow"
0 Kudos
Message 7 of 10
(3,963 Views)

Thank you all very much for your responses. I know you are trying to help.

Maybe I'm not clear as to the problem statement, and the responses are missing the mark.

I will continure to explore this on my own and report back if I should find a solution.

Thanks again.

0 Kudos
Message 8 of 10
(3,942 Views)

I have the same problem now. Did anyone find a solution?

0 Kudos
Message 9 of 10
(3,802 Views)

DM83,

 

I would recommend creating a new forum post that links back to this one with your questions, as the original post hasn't had any activity for clost to 3 years. More users will see the new post and you will be more likely to get an answer. Myself or another applications engineer will continue to monitor the forum should no one have a solution, and we can look into some next steps. 

Will M.
Applications Engineer
National Instruments
0 Kudos
Message 10 of 10
(3,759 Views)