View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rob Bovey Rob Bovey is offline
external usenet poster
 
Posts: 811
Default Renaming File Statement -How does it work??

Hi Fred,

The easiest thing to do would be to stick your cursor on Name in your
code module and press F1. This will bring up the VBA help topic with all the
details. The short answer to your question is that this is a legacy BASIC
function that's not a method of any object and it has no other arguments.

In the case you've shown, it uses the C:\Temp directory by default
because you haven't specified a directory in your arguments and you've set
the C:\Temp directory as the current directory with the ChDir statement. You
could also have done this instead and made it one line of code:

Name "C:\Temp\oldfilename.txt" As "C:\Temp\newfilename.txt"

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm

"KAHAUS" wrote in message
...
Could someone please explain how this Excel 2003 VBA routine works to
rename
a file.
Assume oldfilename.txt exist in the C:\temp directory, when the name
statement executes, it is renamed to "newfilename.txt"

Sub RenameTheFiles()
ChDir "C:\Temp\"
Name "oldfilename.txt" As "newfilename.txt"
End Sub

Originally I was using a multi step routine using the FileSystemObject and
setting a fileObject.Name = new name, thus performing the rename. The
simplicity of this code is confusing what I thought I knew about the
object
models. Specifically, Name in the above routine is a method? How is it
associated, what is the object or how does it know to rename the file in
the
temp directory??? Can anyone give me the complete syntax of the name
statement? I assume there to be several defaults omitted. What role does
the
"AS" play? Is this some kind of shorthand for a SET statement?

Puzzled!

Fred Krause.