FileName

S

Spencer Hutton

Is there a way to rename a file, any file, on my C: drive with this property
in Excel VBA?
 
T

Tom Ogilvy

To rename a closed file
(it must be closed)

oldfile = "C:\My Files\Myfile.txt"
newfile = "C:\My Files\MyNewFile.txt"
name oldfile as newfile
 
J

JWolf

VBA help:

Name Statement


Renames a disk file, directory, or folder.

Syntax

Name oldpathname As newpathname

The Name statement syntax has these parts:

Part Description
oldpathname Required. String expression that specifies the existing file
name and location — may include directory or folder, and drive.
newpathname Required. String expression that specifies the new file name
and location — may include directory or folder, and drive. The file name
specified by newpathname can't already exist.



Remarks

The Name statement renames a file and moves it to a different directory
or folder, if necessary. Name can move a file across drives, but it can
only rename an existing directory or folder when both newpathname and
oldpathname are located on the same drive. Name cannot create a new
file, directory, or folder.

Using Name on an open file produces an error. You must close an open
file before renaming it. Name arguments cannot include
multiple-character (*) and single-character (?) wildcards.
 

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