Trying to write part of a macro to rename a file held in a specific directory. Each day the directory will hold a different file with a different file name however the first several characters will always be the same.
The directory is C:\Report Files\Daily File\ and the file always starts with same characters - 'PCDAILY' (file name is normally something like 'PCDAILY03082012' or 'PCDAILY26072012')
My aim is to rename the file so it's always called 'PCDAILY' (getting rid of all the superfluous numbers) so I can use that name reference throughout the rest of the macro. I am trying to use a wildcard in conjunction with the 'Name' statement to alter the name but cannot get it to work.
Would greatly appreciate any suggestions.![]()
Sub renamer() Dim FileLocation As String Dim OldName As String Dim NewName As String FileLocation = "C:\Report Files\Daily File\" OldName = Left(FileLocation,7) = "PCDAILY" NewName = "PCDAILY.csv" Name FileLocation & OldName As FileLocation & NewName End Sub
Thanks,
Daniel.











LinkBack URL
About LinkBacks
Register To Reply
Bookmarks