LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Excel get workbook names and save only work if LV prog has focus

Hello,

 

the attached program is desigend to get all open excel workbook names and save them every hour before copying them to a server.

 

However the activeX-functions only work, if the LV program has the focus. E.g.: 1. Open "file save'n'copy.vi", 2. open any Excel file -> Workbook name will appear only if "file save'n'copy.vi" gets the focus again. It doesn't save the file without focus also.

 

However "file save'n'copy.vi" is designed to work in the background. So If a PC user forgets to close and save the opened Excel file, "file save'n'copy.vi" saves it and copy it to server every hour.

 

Has anyone a solution?

 

With best regards

0 Kudos
Message 1 of 2
(126 Views)

Without thinking too hard about "is this possible", I'm tempted to suggest that because LabVIEW knows how to open Excel and get Excel to manage .xlsx files for it, the task you are attempting would involve opening a second copy of Excel (while the first still has a Workbook open), "stealing" control of the Workbook, doing something with it, and then returning it to the first Excel program and disappearing from the scene.  I doubt that this is possible (but am happy to be proven wrong).

 

What you might do, instead, is design your (single) Excel routine to run as a Consumer (part of a Producer/Consumer design),  What you want to do is at some convenient interval (it could be every "Write to Excel" command, or "if N minutes elapses without another request to add more data"), get Excel to close any existing Workbook (keeping track of how much it has written), reopen it using the saved version as a Template (which reads it into Excel), and making sure you distinguish between "First Write" (where you might need to write Headers) and "Subsequent Write" (where you only add more data rows).  You have a single program and a single instance of Excel open.  Indeed, you could save up, say, 15 minutes of data in memory, and when you have that much, do the "Open Excel using Template, Write, Save, Close Excel" sequence, initializing by writing a "Template" that has only the header information that would otherwise be unique on the first Write to Excel.

 

I did something like this a bunch of years ago -- it worked well.

 

Bob Schor

0 Kudos
Message 2 of 2
(97 Views)