01-25-2012 10:52 AM
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.
01-26-2012 05:18 PM
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.
01-26-2012 05:44 PM
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.
01-27-2012 08:09 AM
@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?
01-27-2012 09:48 AM
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.
01-27-2012 07:48 PM - edited 01-27-2012 07:51 PM
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/
01-28-2012 03:40 AM
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
01-30-2012 10:28 AM
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.
01-16-2015 04:48 AM
I have the same problem now. Did anyone find a solution?
01-19-2015 08:42 AM
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.