Creating Excel File with Dynamic Names


Is it possible to create a filepath dynamically for Excel?

I am struggling to do it currently

So I want to do something similar to below

ExcelPath = “C:\Path”+Variable+".xlsx"

Thanks in advance

1 Like


Here is something I do from time to time, is replace a word in the string.
For example,

filepath = "c:\path\filename yyyy-MM.xslx"


filepath = "C:\path\filename %date%.xlsx"

or alternatively just simply concatenate variables together like you show. ExcelPath = filepath.Replace(".xlsx","")+variable+".xlsx"

You can also look at a few methods online using Path.GetFilename(), Path.GetExtension(), or Path.GetDirectoryName() and then manipulate the filepath.


1 Like

I’d recommend using String.Format for these:

filepath = String.Format("c:\path\filename {0}.xslx", Now.ToString("yyyy-MM"))
filepath = String.Format("c:\path\filename {0}-{1}.xslx", Now.ToString("yyyy"), Now.ToString("MM"))

Btw - did anyone make interpolated strings work in UiStudio? Syntax doesn’t seem to be correct for some reason, even though it should work.

1 Like

@andrzej.kniola Good idea.
The only thing I have against that method is that you can’t really tell what the {0} is identifying in the string, like what does it represent and what are you putting in its place? I do like that method though and will definitely consider it in the near future.


1 Like

Thanks all for help. That worked

HI All,

I am trying to do the same thing to create dynamic excel file names, but the excel file is not created. Could you please advice if I am missing something.

Capturefile_name=String.Format(“C:\Users\UiPath\demo {0}.xslx”, Now.ToString(“yyyy-MM”))

Newest Excel pack doesn’t create one by default:


To avoid situations when a new workbook was automatically created when the path was not correctly specified, Excel Application Scope now has a new property, Create New File. Once selected, if no workbook can be found at the specified path, a new workbook file is created at the same path.

Hi @RogerFenergo,

I’ve made an example for you to try and understand the dynamic creation of excel files.

excel dyanmic.xaml (14.2 KB)

Just be sure to changes the values of “path” to a folder called “tester” on your desktop. Copy its path and assign that to the path variable.


and don’t include a slash after the last folder as that would cause an error.

Try and see if you can understand the program, and if you face any issues, or if you need an explanation, please feel free to let me know and I’ll try and work it out for you.

All the Best!


EDIT 1: Do add an activity to say, write cell A1, before you execute the bot. I seem to have forgotten to add it. My apologies.