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


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




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






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








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










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
rename excel file name TJ Excel Discussion (Misc queries) 8 June 27th 09 01:56 PM
problem after rename of file vcff Excel Discussion (Misc queries) 7 January 25th 07 01:10 AM
FILE AUTO-RENAME Nimish Excel Discussion (Misc queries) 1 December 7th 06 09:10 PM
How to set SAVE AS file name to equal A1 contents when rename file E Excel Discussion (Misc queries) 0 October 19th 05 08:36 PM
Rename File from list Cesar Zapata[_2_] Excel Programming 1 April 14th 04 06:52 PM


All times are GMT +1. The time now is 12:37 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"