NI Home > Community > NI Discussion Forums

LabVIEW

Reply
Member
Jim77215
Posts: 150
0 Kudos

Open Excel book and select sheet

I need to be able to open an Excel book, select a sheet, and write to a cell. Using the NI examples I've been able to open the excel book but I can't get it to select a sheet within the book. What is the proper way to do this?
Active Participant
Michael_Munroe
Posts: 265

Re: Open Excel book and select sheet

If you are starting with the example Write Table to XL, just change the Workbooks->Add to Workbooks->Open.  Then change the Sheets->Add to Sheets->Item.  The variant that is returned needs to be converted to a Worksheet type just like in the example.  The Index input is a variant and can accept either an integer sheet index or a string sheet name.

If you are expecting the specified sheet to be displayed by the ActiveX Item method, you won't see it.  The reference allows direct read/write of sheet contents without it being visible.  If you need to see it, use the Worksheet->Activate method.

Michael Munroe
Certified LabVIEW Developer, MCP
Member
juiop
Posts: 25
0 Kudos

Re: Open Excel book and select sheet

Hi Michael

 

 I have a few problems with the examples when I try to open XL, it opens continuously and never stops how can i make that excel only open one time ? Because when I run the other examples, I have the same problem it is always opening new windows so I can't work with 'em

Knight of NI
Posts: 18,064

Re: Open Excel book and select sheet

Are you clicking on the Run Continuously button in the toolbar? If so, don't. If not, then please provide more information. The example will open Excel. If you have the front panel control set to "Leave Excel open" then if you run it again it will create a new workbook. Are you opening Excel yourself?
Member
juiop
Posts: 25
0 Kudos

Re: Open Excel book and select sheet

Hi smercurio_fc

 

   Yes, I was doing that. But when i will make the executable, Will I  have the same problem? I think it will run as if I clicked on "Run Continously" right?

 

 

Knight of NI
Posts: 18,064

Re: Open Excel book and select sheet

You should NOT be using the Run Continuously button unless you are doing specific kinds of debugging. A normal VI should use the Run (once) button. If the VI needs to continue running you should use a loop.
Member
juiop
Posts: 25
0 Kudos

Re: Open Excel book and select sheet

Hey man thanks for your answers !