Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
PGM PGM is offline
external usenet poster
 
Posts: 5
Default How to change closed file name - Error: file not found

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.

  #2   Report Post  
Posted to microsoft.public.excel.programming
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.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default How to change closed file name - Error: file not found

The problem appears to be the ":" on the end of your ELSE statement.
Remove it. Here is some culled down code that takes advantage of the fact
your are always working in the same directory:


Dim s as String, sName as String
' File name.
s = "S:\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 = sName

' Identify if existing file created on current date.
If Format(Date, "m-d-yy") = MyDate Then
NewFile = s & MyWorkbook & _
" (" & MyDate & " " & MyTime & ").xls"
'
' fixed next line
'
Else
NewFile = s & MyWorkbook & _
" (" & MyDate & ").xls"
End If

name OldFile as NewFile

End if
--
Regards,
Tom Ogilvy


"PGM" wrote:

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.


  #4   Report Post  
Posted to microsoft.public.excel.programming
PGM PGM is offline
external usenet poster
 
Posts: 5
Default How to change closed file name - Error: file not found

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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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





  #6   Report Post  
Posted to microsoft.public.excel.programming
PGM PGM is offline
external usenet poster
 
Posts: 5
Default How to change closed file name - Error: file not found

Tom,

Thanks for your solution. I thought I had covered all the bases, but
that "/" slipped right past me. I just ran a trial and it does
everything I wanted. I appreciate your taking the time to fine tune
this for me.

Paul

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
R/T error 53 - File Not Found JMay Excel Discussion (Misc queries) 4 October 22nd 08 02:56 PM
Installation Error: File Not Found I h8 sku112.cab New Users to Excel 2 September 25th 08 10:58 PM
Runtime Error '53' File Not Found? et10yl Excel Discussion (Misc queries) 0 November 27th 06 10:49 PM
File not found - error Piranha[_39_] Excel Programming 18 September 19th 05 02:18 AM
"file not found" error message when launching source file Lisa[_9_] Excel Programming 4 April 6th 04 02:54 PM


All times are GMT +1. The time now is 06:54 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"