LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

open file in excel from labview

I need a way to open an existing Excel file, that may or may not be open already.  I am using the attached "Open Specific WorkBook.vi" from the examples.  My LabVIEW program must be able to either open a specifc Excel workbook and worksheet even if it is already open.  Is this even possible, or would it be better to close it (if open), the open it again?
0 Kudos
Message 1 of 6
(4,485 Views)

As you probably know, nothing "bad" happens when you open Excel if it's already open, it just doesn't come to the front of your LabVIIEW ap. To get it to the front, Minimize the Excel window then immediately Maximize it (or Normalize it) programmatically with a PN.  I have tried many of the other methods (but not all of them) to no avail, this works for me. There may be a more elegant solution.

 

There are other known methods to bring an ap to the front, with callbacks etc, but they can be clunky, or require Userlib32, etc. Since this property node already exists in your ap, it's comes at little expense.

 

Of course, you may want to check that the ap was open before you do this, but even that is optional, at the expense of a little flashing on the screen.

Richard






0 Kudos
Message 2 of 6
(4,456 Views)

Thanks for the response.  My problem is that my customer does not want to see the warning message that I am trying to open a workbook that is already open.  I need a way to recognize that it is open, then either add data to it.  OR close it, reopen it, then add data to it.  How can I check to see if a specific workbook is open?

 

Steve

0 Kudos
Message 3 of 6
(4,418 Views)
You can use the Workbooks.Count property to get the number of open workbooks and then drive a for-loop with that. In the loop use the Workbooks.Item() method to get each workbook and then get its name. Then you can simply search the array. Code snippet:
Message 4 of 6
(4,405 Views)

Well done smercurio.

I looked through the methods, and there's just nothing directly related to an IsOpen type VB function.

I guess you could also do a known safe method on the open workbook and look for an error?

Richard






0 Kudos
Message 5 of 6
(4,392 Views)

Broken Arrow wrote:

I guess you could also do a known safe method on the open workbook and look for an error?


That would also work.

0 Kudos
Message 6 of 6
(4,378 Views)