LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Open Excel workbook and worksheet once and continously save data on the same worksheet

I have a While loop where I am continously acquiring data and parsing it out and I want to save this data in one workbook and worksheet. I have used an example that I got from this website where it opens up a workbook and worksheet and so on. But in my loop when i use it obvously it will keep opening a new workbook and worksheet. I need to just open it once and keep appending my data to it. Any help would be appreciated. Thanks
0 Kudos
Message 1 of 6
(3,416 Views)
Since you haven't attached the example, all I can do is explain how the LabVIEW shipping example (Write Table to XL.vi) works and how it can be modified. The shipping example has an Open Excel, Open Book, Open Sheet and, some functions for labeling rows and columns, and then a for loop for adding data. Copy the preliminary stuff for creating and opening and put it in your VI at the very beginning so that it's called once. Then, where you want to repeatedly write, just copy the Add Data function (it's called Set Cell Value.vi) Make sure that you pass it the Excel reference and keep incrementing the row value by the number of rows you write each time. Your example probably does something similar. You just have to find the part that does the actual writing
and separate it out from the initial and closing functions.
Message 2 of 6
(3,416 Views)
Thanks Dennis , I figured it out before I read your answer but this is what I exactly did and It works great! I need to ask one more question. I am saving alot of data per columns so I am running out of columns in excel worksheet , how do I go to next sheet to keep saving my data. Thanks alot
0 Kudos
Message 3 of 6
(3,416 Views)
I have figured it out that I can just have the rows increment instead of columns and that works good. One more thing that I am looking into is that I want to save my data every 15 minutes because my program will be running for 8 hours and I want to make sure if in case the computer decides to breakdown on me that I would have some data which I can go back and retrieve. Thanks for you help
0 Kudos
Message 4 of 6
(3,416 Views)
Norman,

The best way to do this would be to wire either the workbook refnum or the application refnum to another while loop on the block diagram. This loop runs with a 15 minute wait in it. Using the refnum, you can then save the file every 15 minutes.

Another method is to save your data after every so many runs of writing the data. This is probably best done using a similar method, but instead of a timer, use an occurrence or notifier to tell the save event to happen.

Randy Hoskin
Applications Engineer
National Instruments
http://www.ni.com/ask
0 Kudos
Message 5 of 6
(3,416 Views)
Thanks Randy, Would you be able to show me an example , because I am new to ActiveX method. Thanks
0 Kudos
Message 6 of 6
(3,416 Views)