File name change

M

Mark

I have the following code taken from Help and modified for my needs:

Dim OldName, NewName
OldName = "BitApp.dat": NewName = "BitApp.txt" ' Define file names.
Name OldName As NewName ' Rename file.
OldName = "\\D3-ds\misterdev\BITData\BitApp.dat": NewName =
"\\D3-ds\misterdev\BITData\BitApp.txt"
Name OldName As NewName ' Move and rename file.

Running this code produces a run time error “53†File not found.
Any way to rename a file. This should be basic stuff. Probably is. Any
suggestions?
Mark
 
D

Douglas J. Steele

Which invocation of Name fails: the first or the second?

Are you sure that the file does exist?
 
M

Mark

I removed the first and found the second works, however, there is the issue
of the file existing. Do you know the syntax for the check on the file?
Something like:
File.FileExists(\\D3-ds\misterdev\BITData\BitApp.txt)
Thanks,
Mark
 
M

Mark

I found the solution:
Dim OldName, NewName

Set fs = CreateObject("Scripting.FileSystemObject")
If fs.FileExists("\\D3-ds\misterdev\BITData\BitApp.txt") = True Then
Kill "\\D3-ds\misterdev\BITData\BitApp.txt"
End If
If fs.FileExists("\\D3-ds\misterdev\BITData\BitApp.dat") = True Then
OldName = "\\D3-ds\misterdev\BITData\BitApp.dat"
NewName = "\\D3-ds\misterdev\BITData\BitApp.txt"
Name OldName As NewName ' Rename file.
End If

Thanks for your help,
Mark
 
D

Douglas J. Steele

It's overkill to use FSO (plus FSO is slow).

If Len(Dir("\\D3-ds\misterdev\BITData\BitApp.txt")) > 0 Then
Kill "\\D3-ds\misterdev\BITData\BitApp.txt"
End If
If Len(Dir("\\D3-ds\misterdev\BITData\BitApp.dat")) > 0 Then
OldName = "\\D3-ds\misterdev\BITData\BitApp.dat"
NewName = "\\D3-ds\misterdev\BITData\BitApp.txt"
Name OldName As NewName ' Rename file.
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top