LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

write to excel

Solved!
Go to solution

i created a VI that would open excel, write to a sheet then save as original_timestamp (this way i had a clean template each time), the problem i ran into was i opened the original each time so everytime i wrote to new sheet only the most recent sheet had values while the others were empty.  So i split the VI into 3 parts - OpenExcel, WriteToExcel, and CloseExcel.  Now all of my sheet data gets written to the first sheet.  Can someone look at my VIs and let me know if i have a reference problem.  I call these from TestStand and safe the references to variables which i then pass on to the other VIs.

Download All
0 Kudos
Message 1 of 6
(2,693 Views)

You are getting a reference to the active worksheet.  I don't see anywhere that you are opening up a reference to a different worksheet.  So whatever sheet was active the last time the file was saved is the one getting the new data.  And will remain the active sheet when you save and close it.

Message 2 of 6
(2,682 Views)

Would that go into the OpenExcel VI or the WriteData VI?  I thought that since i was passing in the Sheet and setting it active that would clear up the referencing.

0 Kudos
Message 3 of 6
(2,656 Views)

You would want to select the correct worksheet in the WriteData VI I believe for your application.  However, I don't see at all in your code where you set it to active.  I see you use the sheet name to get an item, but you do nothing else with it.

Jesse S.
Applications Engineer
National Instruments
0 Kudos
Message 4 of 6
(2,648 Views)

i've looked it over and don't see where or how to set the active sheet other than the way it is now.  Is there another method i need to use?

0 Kudos
Message 5 of 6
(2,631 Views)
Solution
Accepted by topic author at2bob

Except you are not setting the active sheet now.

 

You do have a invoke node that takes a sheet name and gives you a reference to a worksheet.  Except you never do anything with that reference coming from the "Item" terminal.  You proceed to use the ActiveSheet property and use that sheet.

 

Try eliminating ActiveSheet, and use the output of the Sheets invoke node.

 

If you want to make this sheet the active one (you don't need to because you can work on inactive sheets, but activating it will bring it to the front and save that state when you save the file), you can use the Invoke Node called Activate that is part of the Worksheet object.

Message 6 of 6
(2,628 Views)