LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Excel Automation Closing

Hello,

 

I have developed a VI (based on ActiveX) that writes to a spreadsheet with some formatting. Past posts on this forum were very helpful in getting me at this point and Kudos to members who have posted VIs, LLBs, and created a thread just for Excel automation.

 

I've one question related to Excel application closing:

Currently, I am doing a clean close of all references in my VI for report generation using ActiveX. If I am viewing any open workbooks in excel when my VI is running then it closes all open xls/xlsx files when the "Excel Automation Close" is executed.

My question is: Is it possible to somehow not close instance of Excel application that was not created/opened through LabVIEW?

 

Thanks.

0 Kudos
Message 1 of 5
(3,114 Views)

What you would need to do is to check to see if there's an existing Excel process already running before you "do your thing". If there is, then you will want to just close the workbook rather than closing Excel, which terminates the Excel process.

 

How do you check to see if Excel is already running? You can just use tasklist via System Exec and parse the output. Other solutions have been suggested in the past, so if you search you can find them.

0 Kudos
Message 2 of 5
(3,099 Views)

Thanks, . I will try out the System Exec option.

0 Kudos
Message 3 of 5
(3,091 Views)

Hello,

 

Using the System Exec VI, I am able to get the Process ID of Excel application instance. However, to use the workbook node, Application refnum is required.

Is there a way to get to the Application refnum using the process ID?

 

For now, I have figured out a way to avoid any Excel workbook closing with Automation close. Wiring True to Open New Instance in Open Automation seems to do the trick.

 

Thanks.

0 Kudos
Message 4 of 5
(3,072 Views)

There is no way to convert the process ID to an automation refnum since there is no connection between the two. The only objective of that was to see if Excel was already running so you didn't try to close it.

0 Kudos
Message 5 of 5
(3,058 Views)