View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Doug Glancy Doug Glancy is offline
external usenet poster
 
Posts: 770
Default How to change closed file name - Error: file not found

PGM,

NewFile is an Excel reserved word (I think) so I suppose that cause a
problem.

Also, a shot in the dark. Is it possible that MyWorkbook already includes
an ".xls" extension, so that you are specifying something like
"MyWorkbook.xls.xls"?

What does the whole NewFile string evaluate to?

hth,

Doug

"PGM" wrote in message
oups.com...
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.