Rename file macro

  • Thread starter Thread starter William J. Szabo
  • Start date Start date
W

William J. Szabo

I have two files that I rename every day. I would like to have a
macro that I can initiate (button) that I can push every day and
rename the ex_costprday.xls to ex_costprday-(todays date).xls and then
rename the second file ex_cost.xls to ex_costprday.xls. I then can
compare the previous days transactions with todays and also have a
daily log of the renamed files.

Rename R:\ex_costprday.xls R:\ex_costprday-09-14-04.xls
Rename R:\ex_cost.xls R:\ex_costprday.xls

Thanks in advance for any help.

Bill Szabo
 
Hi Bill

Sub test()
Dim OldName As String
Dim NewName As String

OldName = "C:\Temp\Test.mp3"
NewName = "C:\Songs\Hymn.mp3"

Name OldName As NewName
End Sub

HTH. Best wishes Harald
 
Harald Staff said:
Hi Bill

Sub test()
Dim OldName As String
Dim NewName As String

OldName = "C:\Temp\Test.mp3"
NewName = "C:\Songs\Hymn.mp3"

Name OldName As NewName
End Sub

HTH. Best wishes Harald

Thanks Harald, this looks like it will work but I still need the VBA
syntax to append the current date into the renamed file name.

NewName = "C:\Songs\Hymn-(current date).mp3"

Sorry to be a bother,
Bill
 
Harald Staff said:
Hi Bill

Sub test()
Dim OldName As String
Dim NewName As String

OldName = "C:\Temp\Test.mp3"
NewName = "C:\Songs\Hymn.mp3"

Name OldName As NewName
End Sub

HTH. Best wishes Harald

Harald,
Disregard my previous post. I figured it out and the final code looks like this.

Sub RenamePrday()
Dim OldName As String
Dim NewName As String

OldName = "R:\ex_costprday.xls"
NewName = "R:\ex_costprday-" & Format(Now, "mm-dd-yy") & ".xls"

Name OldName As NewName
End Sub

Thanks for getting me on the right path.
 
Back
Top