LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Program to save and close the opened excel before start the program

Dear all,

 

I have a VI which takes measurements and store them in an Excel worksheet. I will save the excel before application quit 

 

The VI is running well and as many times the Excel application has been left open and forget to close

 

And start of the program there will be an pop up to close the excel sheet  

 

So presently I have to save and close the excel file

 

Can someone tell me how my Labview VI can detect (at the starting) for specific path of Excel application is already open and then save & close it ?

 

Regards, vinay

0 Kudos
Message 1 of 4
(3,624 Views)

The real problem, I believe, is the failure to close Excel (by running Dispose Report) as part of the Exit-processing code in your VI.  I have a routine that runs a series of behavioral tests, using Excel rows as a set of Trial Parameters (about 120 of them) for each Trial, with a few Result Parameters (about 20) being saved at the end of each Trial Row.  My "End Experiment" State tells Excel to "Close and Save" any Excel File that might be open.

 

Here are two Snippets that illustrate the process.  I'm "violating the Spirit of Bob's Rant" by intending to post a "picture", not Code, because I want to show a number of things without resorting to thousands of words, but this is much too specialized (and somewhat proprietary to me) to post in all its gory detail.

 

The first shows how I Manage Excel, via an Action Engine that keeps the Excel Object "Wire" contained within it.  I'm illustrating the "Close and Save" Action, done at the time of Program Exit.

Excel Close and Save.png

The first thing this does is call WorkBook Active (next Snippet), which returns "True" if there is an Active (i.e. Open) Excel WorkBook, and False if either (a) Excel is Closed or (b) Excel is Open but there is no open WorkBook.  If True, it Saves the Report (if there is one) and then Disposes of Excel, otherwise it does nothing.

 

Workbook Active.png

Here is WorkBook Active.  It tries to get the ActiveX References of the Excel Object.  If Excel is not running, Error 41000 is thrown and trapped, returning Workbook Active = False (Case not shown).  Otherwise, we use the Application property to check for ActiveWorkbook and return True if there is a non-empty Reference.

 

Hope this gives you some ideas and helps with your question.

 

Bob Schor

 

Message 2 of 4
(3,595 Views)

thanks for replaying

 how can I close specific excel file that already opened in window

for example: I have opened A, B & C excel files and if A is opened it should show indication true and save & close the A and B and C remain open

thank u

 

0 Kudos
Message 3 of 4
(3,579 Views)

I'm not quite sure I understand what you are asking.  Are you using LabVIEW to open/create three reports at the same time in Excel, using three Excel Object Wires, each created by a separate New Report function?  If so, you could certainly save one or more by doing a Save Report on its wire, but Excel will still be open until you do Dispose Report (unless you do some funky ActiveX command, which I prefer to leave alone, if possible).  The worry is that if you do close Excel, you may lose the other two Reports that haven't been saved ...

 

Bob Schor

0 Kudos
Message 4 of 4
(3,566 Views)