rename file

prasadgov

Member
Local time
Yesterday, 20:06
Joined
Oct 12, 2021
Messages
114
Hi,

I get a file loaded everyday into a folder in C named as in stock_distribution_20240726.xlsx.
The format is stock_distribution_yyyymmdd.xlsx.

I need to rename this file as stock_distribution.xlsx by stripping off the date before linking it to my table.
Using FileSystemObject and fileExists, I can test if the file exists for that day.
Not sure if I can use Rename along with Mid function to derive only the filename without date.
Is there a simpler way?

TIA
 
You would want Left() surely?, but as you know the name you want, just Name it?
 
For today's date, you could try:
Code:
Replace(Filename, "_" & Format(Date(), "yyyymmdd", "")
Hope that helps...

PS. Just realized you would run into issues if that name already exist in the folder.
 

Users who are viewing this thread

Back
Top Bottom