remove the date from filename

dhen21dx

Board Regular
Joined
May 10, 2013
Messages
166
Hello,

I am trying to rename the my file to delete the date on Reports_20200919, but there is an error on the code.
Please help.

VBA Code:
OldName = CurrentProject.Path & "\Import File\Reports_*" & ".csv"
Filepath1 = CurrentProject.Path & "\Import File\Report.txt"

Name OldName As Filepath1
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
You can use the Dir function to retrieve the actual filename. Try something like this...

VBA Code:
    Dim source_folder As String
    source_folder = CurrentProject.Path & "\Import File\"
    
    Dim old_name As String
    old_name = source_folder & Dir(source_folder & "Reports_*.csv", vbNormal)
    
    Dim new_name As String
    new_name = source_folder & "Report.txt"
    
    Name old_name As new_name

Hope this helps!
 
Upvote 0
Hello Domenic,

Thanks, that works.. the next time, i use the Dir function.. really appreciated for this learnings.
 
Upvote 0

Forum statistics

Threads
1,215,455
Messages
6,124,935
Members
449,195
Latest member
Stevenciu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top