ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Rename file (https://www.excelbanter.com/excel-programming/304139-rename-file.html)

Always Learning

Rename file
 
Good morning guys,

does any one know how I can rename a file using VBA code.

I display a file dialog box allowing the user to pick a .csv file. Because
of the quirks of Excel I need that file to come in as a .Txt file.
I do not want the user to have to rename the file as the existing .csv file
is created by a third party program. My VBA macro then reads the .Csv file
and does it's thing. I need it to be .Txt. How do I rename the file in the
directory before I open it.

Thanks for any help.

Best Regards,

Steve Wilson.



Rob van Gelder[_4_]

Rename file
 
Name statement:
Dim OldName, NewName
OldName = "OLDFILE": NewName = "NEWFILE" ' Define file names.
Name OldName As NewName ' Rename file.

OldName = "C:\MYDIR\OLDFILE": NewName = "C:\YOURDIR\NEWFILE"
Name OldName As NewName ' Move and rename file.

--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Always Learning" <NoMoreSpam@MyEmail wrote in message
...
Good morning guys,

does any one know how I can rename a file using VBA code.

I display a file dialog box allowing the user to pick a .csv file. Because
of the quirks of Excel I need that file to come in as a .Txt file.
I do not want the user to have to rename the file as the existing .csv

file
is created by a third party program. My VBA macro then reads the .Csv file
and does it's thing. I need it to be .Txt. How do I rename the file in the
directory before I open it.

Thanks for any help.

Best Regards,

Steve Wilson.





Always Learning

Rename file
 
Hi Rob,

Fantastic. Works like a charm, Thank you.

Is there a way that I can just copy the file rather than renaming and then
deleting the file so I leave everything as it was?

I appreciate your help.

Best Regards,


Steve Wilson.

"Rob van Gelder" wrote in message
...
Name statement:
Dim OldName, NewName
OldName = "OLDFILE": NewName = "NEWFILE" ' Define file names.
Name OldName As NewName ' Rename file.

OldName = "C:\MYDIR\OLDFILE": NewName = "C:\YOURDIR\NEWFILE"
Name OldName As NewName ' Move and rename file.

--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Always Learning" <NoMoreSpam@MyEmail wrote in message
...
Good morning guys,

does any one know how I can rename a file using VBA code.

I display a file dialog box allowing the user to pick a .csv file.

Because
of the quirks of Excel I need that file to come in as a .Txt file.
I do not want the user to have to rename the file as the existing .csv

file
is created by a third party program. My VBA macro then reads the .Csv

file
and does it's thing. I need it to be .Txt. How do I rename the file in

the
directory before I open it.

Thanks for any help.

Best Regards,

Steve Wilson.







Tom Ogilvy

Rename file
 
Just move it with the same name using the code provided.
OldName = "C:\MYDIR\OLDFILE.xls": NewName = "C:\YOURDIR\OLDFILE.xls"
--
Regards,
Tom Ogilvy

"Always Learning" <NoMoreSpam@MyEmail wrote in message
...
Hi Rob,

Fantastic. Works like a charm, Thank you.

Is there a way that I can just copy the file rather than renaming and then
deleting the file so I leave everything as it was?

I appreciate your help.

Best Regards,


Steve Wilson.

"Rob van Gelder" wrote in message
...
Name statement:
Dim OldName, NewName
OldName = "OLDFILE": NewName = "NEWFILE" ' Define file names.
Name OldName As NewName ' Rename file.

OldName = "C:\MYDIR\OLDFILE": NewName = "C:\YOURDIR\NEWFILE"
Name OldName As NewName ' Move and rename file.

--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Always Learning" <NoMoreSpam@MyEmail wrote in message
...
Good morning guys,

does any one know how I can rename a file using VBA code.

I display a file dialog box allowing the user to pick a .csv file.

Because
of the quirks of Excel I need that file to come in as a .Txt file.
I do not want the user to have to rename the file as the existing .csv

file
is created by a third party program. My VBA macro then reads the .Csv

file
and does it's thing. I need it to be .Txt. How do I rename the file in

the
directory before I open it.

Thanks for any help.

Best Regards,

Steve Wilson.









Always Learning

Rename file
 
Hi Tom,
Thanks for taking the time to respond.

Your answer is so simple and obvious I want to know why didn't I think of
that?
I am always trying to think of the big answer when there is an obvious one.

Best Regards,

Steve Wilson.

"Tom Ogilvy" wrote in message
...
Just move it with the same name using the code provided.
OldName = "C:\MYDIR\OLDFILE.xls": NewName = "C:\YOURDIR\OLDFILE.xls"
--
Regards,
Tom Ogilvy

"Always Learning" <NoMoreSpam@MyEmail wrote in message
...
Hi Rob,

Fantastic. Works like a charm, Thank you.

Is there a way that I can just copy the file rather than renaming and

then
deleting the file so I leave everything as it was?

I appreciate your help.

Best Regards,


Steve Wilson.

"Rob van Gelder" wrote in

message
...
Name statement:
Dim OldName, NewName
OldName = "OLDFILE": NewName = "NEWFILE" ' Define file names.
Name OldName As NewName ' Rename file.

OldName = "C:\MYDIR\OLDFILE": NewName = "C:\YOURDIR\NEWFILE"
Name OldName As NewName ' Move and rename file.

--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Always Learning" <NoMoreSpam@MyEmail wrote in message
...
Good morning guys,

does any one know how I can rename a file using VBA code.

I display a file dialog box allowing the user to pick a .csv file.

Because
of the quirks of Excel I need that file to come in as a .Txt file.
I do not want the user to have to rename the file as the existing

..csv
file
is created by a third party program. My VBA macro then reads the

..Csv
file
and does it's thing. I need it to be .Txt. How do I rename the file

in
the
directory before I open it.

Thanks for any help.

Best Regards,

Steve Wilson.












All times are GMT +1. The time now is 05:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com