I have code working to export a datatable to an excel file on my desktop but it seems that if ran again it will just continue to over write that file. Is there a way to make the file name dynamic so that each time I run the script an the excel file is saved to the desktop and dosent over write the previous file?
I was thinking about just having a date populate in the name...any ideas?
Answer by Michaeldx · Jan 10 at 10:01 PM
One thing you could do is append a time/date stamp to the file name. This not only would make it unique, but also tell you when the file was created. For example, after setting your filename in a variable:
MyFilename = MyFilename + cstr(Now)
Note that the format of this date would be as m/dd/yyy HH:MM:SS AM/PM so you would need to format it in a file system compatible format and one that you like. For formatting of a date, see this page at w3schools.