02-13-2015 11:29 AM
I have an excel template that I have created. I am opening that template, saving it under a different name, and then writing and saving data to that excel sheet at regular intervals. It is giving me an error 5, I understand what this means and I am trying to work around it. However after too many hours spent trying to figure it out, I have asked for any help or input. I have attached an example vi, not the actual one since it is very involved.
Thanks
Solved! Go to Solution.
02-13-2015 12:21 PM
At the very least you have to move the save file step outside of the for loop.
02-13-2015 01:24 PM - edited 02-13-2015 01:25 PM
On a side note do this.
Not this
02-13-2015 03:07 PM
02-13-2015 06:38 PM
02-14-2015 02:34 PM
This snippet encapsulates most of the previous suggestions, and adds a few of my own.
The first code shows one (simplified) way of building the output file name. It incorporates the Build Path function to combine Report File Path with the file name (don't need initial "\"), builds the File Name with Format into String, getting the Time part of the name from Format Date/Time String. I also use Build Path to get the Template path. Inside the For Loop, another Format into String gets the data that is placed in the 10 Excel cells. We don't write anything yet -- we're only filling in the cells in the WorkSheet (think of how you use Excel -- you could, but probably don't, save the WorkBook after every cell entry, you wait until you are all done and then do a Save, followed by closing Excel). Finally, when we are done, we save the file using the output name we want to use, then close Excel (which disposes of the Report Object). If we want to generate another report, with another (time-based) name, we can put this code into a sub-VI and simply call it again.
Don't worry if you don't have LabVIEW 2014 (which was used to save this snippet) -- most of the code comes from the original that you posted, so it should be a pretty simple edit to change that code to match this.
Bob Schor
02-14-2015 04:16 PM
02-16-2015 12:39 PM
I understand that I can save after I put in the information and it works fine, I have tried that. However the question was how can I save inside the for loop. The problem is I am running a test that is going to be running over the course of several days. Essential each iteration is a new measurement and write to excel, and I want to save the measurement to a network drive in Excel so that it itsn't deleted in the case of a power failure.
I appreciate the advice on the time stamp and thanks for all your replies! I appreciate the help.
02-16-2015 01:53 PM
02-16-2015 09:32 PM
I don't quite understand your recording scenario. Pretend that I'm trying to do this manually, say once every 5 minutes. The question is, what do I do every 5 minutes?
Do you see the distinction? Scenario 1 is basically what I outlined -- as often as you want (every 5 minutes), you open Excel, take some data, and save it as a unique file. You end up with many WorkBooks, each holding one session's readings.
Scenario 2 gathers all of the readings into a single WorkBook. For safety, you open and close the WorkBook before/after each reading. Like the first Scenario, there is the "cost" of opening/saving/closing Excel for each recording session, plus "saving the data" at the end.
Scenario 3 puts the opening/closing of Excel outside the loop. I'm not sure if you can do the equivalent of File/Save with a LabVIEW function, and am also unsure what would happen if the PC "crashed" after a Save -- the data would probably be OK.
BS