P
PGM
Hello,
I've been trying to write code in Excel 2003 to change the name of a
closed file. This is to prevent a new version of a form from
overwriting the old file. I used the code provided by Tom Ogilvy back
in 2004 (in addition to another function whose author name I don't
currently have handy), but every time I try to run the macro, I get an
error message that the file is not found. An example of my code is
shown below:
MyState, MyAgyNum, MyYear and MyWorkbook have been previously defined
via userform.
' File name.
sName = "S:\Dept\GROUP\CITY\STATE\Auto Agency Reports\" & MyState &
" Auto Reports\" & MyAgyNum & "\" & MyYear & "\VERSION\" & MyWorkbook &
".xls"
If Dir(sName) <> "" Then
' Get properties with Function: File_Created_Info.
MyCreated =
File_Created_Info("S:\Dept\GROUP\CITY\STATE\Auto Agency Reports\" &
MyState & " Auto Reports\" & MyAgyNum & "\" & MyYear & "\VERSION\" &
MyWorkbook & ".xls")
' 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:\Dept\GROUP\CITY\STATE\Auto Agency Reports\" &
MyState & " Auto Reports\" & MyAgyNum & "\" & MyYear & "\VERSION\" &
MyWorkbook & ".xls"
' Identify if existing file created on current date.
If Format(Date, "m-d-yy") = MyDate Then
NewFile = "S:\Dept\GROUP\CITY\STATE\Auto Agency
Reports\" & MyState & " Auto Reports\" & MyAgyNum & "\" & MyYear &
"\VERSION\" & MyWorkbook & " (" & MyDate & " " & MyTime & ").xls"
Else:
NewFile = "S:\Dept\GROUP\CITY\STATE\Auto Agency
Reports\" & MyState & " Auto Reports\" & MyAgyNum & "\" & MyYear &
"\VERSION\" & MyWorkbook & " (" & MyDate & ").xls"
End If
' >>>>>>>This is what fails every time.<<<<<<<
Name oldfile As NewFile
Thanks in advance for any help you can provide.
I've been trying to write code in Excel 2003 to change the name of a
closed file. This is to prevent a new version of a form from
overwriting the old file. I used the code provided by Tom Ogilvy back
in 2004 (in addition to another function whose author name I don't
currently have handy), but every time I try to run the macro, I get an
error message that the file is not found. An example of my code is
shown below:
MyState, MyAgyNum, MyYear and MyWorkbook have been previously defined
via userform.
' File name.
sName = "S:\Dept\GROUP\CITY\STATE\Auto Agency Reports\" & MyState &
" Auto Reports\" & MyAgyNum & "\" & MyYear & "\VERSION\" & MyWorkbook &
".xls"
If Dir(sName) <> "" Then
' Get properties with Function: File_Created_Info.
MyCreated =
File_Created_Info("S:\Dept\GROUP\CITY\STATE\Auto Agency Reports\" &
MyState & " Auto Reports\" & MyAgyNum & "\" & MyYear & "\VERSION\" &
MyWorkbook & ".xls")
' 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:\Dept\GROUP\CITY\STATE\Auto Agency Reports\" &
MyState & " Auto Reports\" & MyAgyNum & "\" & MyYear & "\VERSION\" &
MyWorkbook & ".xls"
' Identify if existing file created on current date.
If Format(Date, "m-d-yy") = MyDate Then
NewFile = "S:\Dept\GROUP\CITY\STATE\Auto Agency
Reports\" & MyState & " Auto Reports\" & MyAgyNum & "\" & MyYear &
"\VERSION\" & MyWorkbook & " (" & MyDate & " " & MyTime & ").xls"
Else:
NewFile = "S:\Dept\GROUP\CITY\STATE\Auto Agency
Reports\" & MyState & " Auto Reports\" & MyAgyNum & "\" & MyYear &
"\VERSION\" & MyWorkbook & " (" & MyDate & ").xls"
End If
' >>>>>>>This is what fails every time.<<<<<<<
Name oldfile As NewFile
Thanks in advance for any help you can provide.