How to change closed file name - Error: file not found
I created you directory structure (using my own values for your variable
values) and this worked for me. It appears you think you are formatting
your date as m-d-yy, but you are not. It was being formatted with "/"
with is an illegal character.
Anyway, as I said, it worked for me.
Sub AAA()
Dim s As String, sName As String, t As String
MyAgyNum = "D199"
MyState = "Virginia"
MyYear = 2005
MyWorkbook = "AA_Paul"
' File name.
s = "D:\Dept\GROUP\CITY\STATE\Auto Agency Reports\" & _
MyState & " Auto Reports\" & MyAgyNum & "\" & _
MyYear & "\VERSION\"
sName = s & MyWorkbook & ".xls"
If Dir(sName) < "" Then
' Get properties with Function: File_Created_Info.
MyCreated = File_Created_Info(sName)
' Identify Date and Time.
MyDate = Left(MyCreated, _
InStr(MyCreated, " ") - 1)
MyTime = Format(Right(MyCreated, _
Len(MyCreated) - _
InStr(MyCreated, _
" ")), "hh:mm;@")
' Format time for file name.
MyTime = Left(MyTime, 2) & "." & _
Right(MyTime, 2)
' Identify file to change.
Oldfile = s & MyWorkbook & ".xls"
' Identify if existing file created on current date.
If CDate(Date) = CDate(MyDate) Then
NewFile = s & MyWorkbook & _
" (" & MyDate & " " & MyTime & ").xls"
Else
NewFile = s & MyWorkbook & _
" (" & MyDate & ").xls"
End If
NewFile = Application.Substitute(NewFile, "/", "-")
MsgBox Oldfile & "-" & NewFile
Name Oldfile As NewFile
End If
End Sub
--
regards,
Tom Ogilvy
"PGM" wrote in message
ups.com...
Doug,
Thanks for the suggestion. I changed NewFile to MyNew File.
Tom,
I appreciate the suggestions. I removed the colon from the ELSE
statement, in addition to changing the variable name as suggested by
Doug. Alas, I still get Error 53: File not found when I step into
Name MyOldFile As MyNewFile.
I am open to any other suggestions, else I'll need to modify the code
to open the old file, save it with the new information then kill the
old file.
Thanks again!
Paul
|