LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to determine when vi-launched Excel session is closed

I have an application in LV 7.1 (DS-PCE) where a VI opens an Excel spreadsheet to view a "logbook"
of prior user activity in response to a "view logbook" button. Other tasks in the VI also access the same
file via Excel report generation VI's.  The main application keeps the Excel session refnum around once it
is opened and if a new action needs to open the file, closes the old session if it is still open and restarts
Excel. Clumsy but functional. Actually, the session is closed even if the user closed the excel session
independently of the VI.

I would like to be able to detect that the spawned Excel session is no longer open and dispose of the
refnum at that time, rather than assuming a session is still open and taking actions to close it (I am
suspicious that such ambiguous actions are responsible for problems terminating the VI when
deployed as a standalone).

Any suggestions of a "clean" way to do this?

Thanks!

Bob


0 Kudos
Message 1 of 4
(2,719 Views)

I'm pretty new to the ActiveX control of MS Excel but I did notice that there is a 'Ready' boolean available if you wire a property node to the refnum.  Perhaps you could use that.  Or else try to read the 'Name'.  If you get "MS Excel" back it's open if you get an empty string and an error 97 the refnum is invalid and Excel must be closed. 

There are probably more elegant ways to do this. Maybe an ActiveX guru can give us both some ideas?

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019
0 Kudos
Message 2 of 4
(2,714 Views)
Hmmm. My inexperience is probably showing, but how do you attach a property node to this
refnum? (generated by the "New Report" VI). I tried the property node in the VI server
palette, but as the refnum does not point to a VI, it was the wrong type to wire to that
property node.  I found no other such goodie in the report generation palette.

I did find a "get report type" VI in the report palette which I figured could do the same thing.
But while the VI squawked appropriately before Excel had been launched, it didn't notice at
all when it was closed (outside of the VI) by the user. Diving into the VI to see just what it was
doing, I got to the "Generate Report object Repository" vi whose block diagram was *locked*
(by NI). Grrrrr.

Bob
0 Kudos
Message 3 of 4
(2,701 Views)
I just used the one in the Application Control palette.  I'm pretty sure the Reference, Invoke, and Property Nodes are all the same wherever you get them.  I've been working more on the ActiveX functions since I have to add more advanced report generation into some programs.  Take a look at the ActiveX and Excel examples for some guidlines on how to get started.  If I come up with a good way to address your issue I'll be sure to let you know.
LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019
0 Kudos
Message 4 of 4
(2,689 Views)