Excel - Option to Increment Filename if File Exists

Feature Request:

Within the excel actions, an option to increment file names when saving as a new file (…_0.xlsx, …_1.xlsx, …_2.xlsx, …) if that file name already exists. This would be a huge time saver.

Thanks!

You can do this with the actions provided while waiting for WF to build this feature request. I have a bot that creates a unique .txt file for logs based on time created whenever I run it and the same logic (with a few tweaks) could be applied to your situation.

This is how would do it in Excel.

  1. Have the full path of the file you want the bot to save into and insert it into the “File name”. Choose the correct file type to save as and then press save.
  2. Excel will prompt a “Confirm Save As” window and you can set a boolean to keep track of whether this window exists or not. If that window exists, select “No”. If that window does not exist that means a unique file has been created and saved.
  3. Update the path by appending a suffix like “_” & "${counter} to the file name and then try saving again.
  4. Increment ${counter} when the bot has successfully saved a new unique file.

I would imagine the same logic above can be applied to the same excel actions.

2 Likes

Thanks for this, @tinwy! I have a similar module for naming excel files already that uses a boolean variable, while loop, and counter variable - while file exists boolean variable equals true, try to open file name_counter; if the file can’t be opened, exit the loop and save. If it can be opened, keep increasing the counter and try to open until the file can’t be opened (doesn’t already exist) then save.

2 Likes