LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Opening an Excel workbook with multiple sheets

I have modified an existing LabVIEW program that reads data from two humidity transmitters and write the acquired data to two sheets of an Excel workbook.  The previous program used DDE; this version uses ActiveX.  The program operates correctly if I open an existing Excel file.  If I create a new file for writing in the attached vi, ActiveX Open Excel.vi, the new workbook is opened in read-only mode with a single sheet.  After ~10 seconds, I get a message stating that the new file "is now available for editing.  Choose Read-Write to open it for editing.", with "Read-Write" and "Cancel" buttons on the dialog box.  If I run this vi as a subVI in my main progam, this causes an incorrect index error when the program attempts to write data for the 2nd transmitter.  Is it possible to open a new Excel workbook with multiple worksheets from LabVIEW?
0 Kudos
Message 1 of 5
(6,762 Views)

You are improperly using the Open/Create/Replace VI.  This is perfect when you use this reference for writing data to the file in LV.  By specifying Read/Write this VI is locking access to the file until the reference is automatically disposed of.

Use the File Dialog VI instead.  It returns the full path to the selected file without opening it.  Check the canceled output to see if the user did not select a file.

The number of sheets in a new workbook is set by the Excel configuration.  Go to Tools->Options->General and you will see the setting.  If you will be running on another computer later then use Sheets.Count to determine how many there are in the new workbook and Sheets.Add to add the second sheet.

Michael Munroe, CLD, CTD, MCP
Automate 1M+ VI Search, Sort and Edit operations with Property Inspector 5.0, now with a new Interactive Window Manager!
Now supports full project automation using one-click custom macros or CLI.
0 Kudos
Message 2 of 5
(6,746 Views)
Thanks for the info.  I am now able to open a new Excel workbook with multiple tabs.  I couldn't get the File Dialog vi to do this, though.  I placed that vi and configured it for new or existing files.  When I ran the vi, I was able to select an existing workbook with no problem.  If I typed in the name of a new file, however, the dialog box accepted the name, but the vi produced an error message stating that it could not find the file.  I added a call to Close File after the call to Open/Create/Replace and passed the path output by this to Invoke Node.  This worked fine.   I did have to get the sheet count and add an additional sheet, even though the Excel option is set to open with 3 worksheets (which is how it  works if I create a new workbook directly from Excel).
0 Kudos
Message 3 of 5
(6,734 Views)

Sounds like you are writing an empty file to trick Excel when the user wants to create a new file.  When you open this in Excel it will be parsed as a Text file.  That is why you only have one sheet.

I recommend that you check for the File Info of the specified file and use a case statement to select between Workbooks.Open and Workbooks.Add.  You can also use the Error Out of the Open to insert the Add into the sequence.  After the Workbook is added you can  SaveAs to create a valid Excel workbook file.

Michael Munroe, CLD, CTD, MCP
Automate 1M+ VI Search, Sort and Edit operations with Property Inspector 5.0, now with a new Interactive Window Manager!
Now supports full project automation using one-click custom macros or CLI.
0 Kudos
Message 4 of 5
(6,717 Views)

Hello! 

 

Please could you do me a favor and attach a working VI where I can save data into multiple excel sheets?

 

Thanks very much!

 

 

Bill 

0 Kudos
Message 5 of 5
(5,887 Views)