Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Move and rename a file

Calling all Excel programming brains,

I am trying to move and rename a file but don't know where to start,
can anybody help?

Thanks,
Peter

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Move and rename a file


Lookup "Name Statement" in VBA Help

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.



On Jan 27, 1:24 am, "Peter" wrote:
Calling all Excel programming brains,

I am trying to move and rename a file but don't know where to start,
can anybody help?

Thanks,
Peter


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Move and rename a file

Peter,

Depending on what you actually want to do, try something like

Sub AAA()
Dim DestinationFolder As String
Dim SourceFileName As String
Dim DestinationFileName As String

DestinationFolder = "C:\Test" '<<< CHANGE
SourceFileName = "C:\Test1.txt" '<<< CHANGE
DestinationFileName = "C:\Test\Test2.txt" '<<< CHANGE

If Dir(DestinationFolder, vbDirectory + vbHidden) = vbNullString Then
' folder does not exist, create it
MkDir DestinationFolder
End If

'''''''''''''''''''''''''''''''
' If you want to COPY the file,
'''''''''''''''''''''''''''''''
FileCopy SourceFileName, DestinationFileName

'''''''''''''''''''''''''''''''
' If you want to MOVE the file.
'''''''''''''''''''''''''''''''
Name SourceFileName As DestinationFileName
End Sub

You'll probably want to add some error checking to ensure the file exists,
and the destination file does not exist, but the code above should get you
started.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email on the web site)

"Peter" wrote in message
oups.com...
Calling all Excel programming brains,

I am trying to move and rename a file but don't know where to start,
can anybody help?

Thanks,
Peter



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
Cannot Move, Copy, Insert, Rename, or Delete a Worksheet in Any Wo JG Excel Discussion (Misc queries) 6 February 4th 09 06:42 PM
Move and rename a file Peter[_61_] Excel Programming 2 January 26th 07 04:13 PM
Open a sheet rename and move to another workbook Patrick[_14_] Excel Programming 16 August 19th 06 04:24 AM
Rename or move file function InventoryQueryGuy Excel Programming 4 August 11th 06 06:02 PM
Insert sheet, move to end, rename with cell data. [email protected] Excel Discussion (Misc queries) 2 October 11th 05 03:04 PM


All times are GMT +1. The time now is 03:51 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"