I'm using the following code and need to change it so that the date is added at the end of the new file name. I tried adding this: & Format(Date, "YYYYMMDD") & ".xlsx" but can't seem to get it in the correct location or maybe that just won't work. Can someone please help me rewrite the code?
Sub RenameCMAnalysis()
Dim fPATH As String, fName As String, NwNAME As String, NUM As Long
fPATH = "\\ltcgsrv1\Cognos\Cognos Report Output\Deck Reports\CM Analysis Reports\"
fName = Dir(fPATH & "*-en-us*.*") 'grab first filename with a -en-us in that name
Do While Len(fName) > 0
NUM = 1
Do
NwNAME = Left(fName, InStr(fName, "-en-us") - 1) & Right(fName, Len(fName) - InStrRev(fName, ".") + NUM)
If Len(Dir(fPATH & NwNAME)) = 0 Then Exit Do
NUM = NUM + 1
Loop
Name fPATH & fName As fPATH & NwNAME
fName = Dir(fPATH & "*-en-us*.*")
Loop
End Sub
Bookmarks