From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to read particular sheet from excel file?

Hi,
 I have a simple query. I have a 10 sheet in my excel file and I want to read the sheet number 6 (or any 1-10). How can I do this?
 
Thanks:-
Mike.
0 Kudos
Message 1 of 5
(2,879 Views)
Hello Mike,

This rather messy labview code image below should get you going.

Cheers,

Victor


Message 2 of 5
(2,865 Views)
While the wiring is a bit messy, there's parts of it that don't seem to make too much sense:
  • You open Excel, and access the ActiveWorkbook, and then open a specific workbook. Why are you accessing the ActiveWorkbook?
  • You access the Sheets property of the workbook you opened, close the workbook reference, then access the Worksheets property of the Excel application. You only use the Sheets property of the workbook just to get the number of sheets. You already have the Sheets from the workbook, why do you need to access the Worksheets property of the Excel application?
To original poster: Open the Example Finder (Help->Find Examples). Change to the Search tab, and enter "Excel" in the search box. Open the example called "Excel Macro Example". In there you will find 3 VI that you need: "Open Excel and Make Visible", "Open Specific Workbook", and "Open Specific Worksheet". You should copy the VI to your working directory and use them in your code. The "Open Specific Worksheet" has a constant of "1" wired in the block diagram to always open worksheet 1. All you need to do is replace this with a control to open a specific sheet. The "Excel Macro Example" also shows you the correct order in closing the references.
0 Kudos
Message 3 of 5
(2,851 Views)
Hello smercurio_fc,
The code in my example was done years ago and has had stuff added and taken away quite a few times so there is not much logic going on. It does actually work though!
The ActiveWorkbook ref was part of some error checking so it should be ignored (I should have edited this out to make it more relevant). Thanks for pointing out the LabVIEW example.
Zing

0 Kudos
Message 4 of 5
(2,846 Views)

Thanks a lot for your help.

 

Mike

0 Kudos
Message 5 of 5
(2,830 Views)