07-27-2017 02:04 PM
Hello,
I am attempting to index the worksheet name of an excel workbook. If You run the code a second time, you get an error because the name already exists. How to go about adding a new sheet each time with a number added to the original sheet name each time. So, for the second run, the name will be TESTNAME_1, the third run will have the name TESTNAME_2 and so on.
Thanks,
Solved! Go to Solution.
07-27-2017 02:37 PM
What about inserting this for filenames and increments?
07-27-2017 03:15 PM - edited 07-27-2017 03:23 PM
Thanks!
07-27-2017 03:24 PM
There is no TRUE case, the other case is the empty string "" case which passes the TESTNAME input on to the worksheet name input. The earlier attached file is a snippet. Open the attachment, then drag it across to the block diagram for all of the details.
07-27-2017 04:14 PM
I put your code into a state machine, but the second iteration gets an error. The attached program generates the name 001.
Please let me know what I did wrong?
Also, is there a way to create a new excel file if one does not exist?
Thanks!
07-27-2017 05:46 PM - edited 07-27-2017 05:47 PM
OK, I got it to work partially (the "True" case= ""). On the third iteration, the name come out as "TESTNAME001001". The fourth iteration, the names comes out as "TESTNAME001001001". How can we fix this?
Thanks.
07-27-2017 06:34 PM
I think you will need to make some assumptions about your data and decide what format you want.
For example, assume you had the following names
TestName, TestName1,TestName, TestName1
would you want the names to be TestName, TestName1, TestName2,TestName3, or
would you want the names to be TestName, TestName1, TestName_1,TestName1_1, etc
Steps for the first case.
Attached is a method, 2015 Version, with credit due to Altenbach as part of code is his from a post somewhere on the discussion forums. Test the code with a list of names, or empty strings and modify as needed.
Cheers,
mcduff
PS Hopefully, Altenbach will post something much smaller than my superfluous code.
07-28-2017 07:16 AM
Modify the false case as attached.
This will allow for the tab names to be TESTNAME, TESTNAME_001, TESTNAME_002,...
If you have more than 1000 files, then adjust the %03d to handle the maximum number of desired files.
07-28-2017 08:20 AM
Didn't you already ask this question as an "add-on" to your earlier post, "Rename Excel Worksheets"? There I told you how to name a sheet "MODULATION_1" if there was already a sheet named "MODULATION".
Have you actually tried to implement any of the suggestions we've given you, or are you just waiting for one of us to "hand you a complete solution" to your problem?
Bob Schor
07-28-2017 09:51 AM
@mcduff wrote:
PS Hopefully, Altenbach will post something much smaller than my superfluous code.
I don't quite recognize the code, but my memory is no longer what it never was. 😄 Do you have a link? (I don't want to receive false credit, especially if the code contains things I would never do, such as abuse a while loop as a fake FOR loop. 🐵
In any case, LabVIEW has a tool named "create file with incrementing suffix" in the advanced file palette and the code is not locked. I am sure it would be trivial to copy and re-use the core of the code and apply it to worksheet names. We are just dealing with strings! No need to re-invent the wheel 😄