View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Move File to New Directory

David,

See http://www.cpearson.com/excel/clonefolder.htm . This will create a new
folder from an existing folder, copying all files and subfolders from the
source folder to the destination folder. All files and subfolders from the
source folder are copied to the destination folder. The subfolder hierarchy
that exists in the source folder (subfolders of subfolders of subfolder,
etc) are preserved in the destination folder.

If you know a folder name but not its Parent folder name, you can use the
Scripting.FileSystemObject to get the parent folder. E.g.,

Dim FSO As Scripting.FileSystemObject
Dim KnownFolderName As String
Dim ParentFolderName As String

Set FSO = New Scripting.FileSystemObject
KnownFolderName = "C:\Temp Folder\New Folder"
ParentFolderName = FSO.GetFolder(KnownFolderName).ParentFolder.Path
Debug.Print ParentFolderName

For the code above, you'll need a reference to the Microsoft Scripting
Runtime library. In VBA, go to the Tools menu, choose References, and find
"Microsoft Scripting Runtime" in the list and check that item.

The CloneFolder code does a Copy operation, not a Move operation. You could
modify the code to delete the source folder at the end of the operation (see
http://www.cpearson.com/excel/recycle.htm for code to send a file or folder
to the Recycle Bin --safer than using Kill to get rid of files/folders).


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


"David" wrote in message
...
I have a workbook that posts to two other workbooks. As part of the setup
process, all three files are in the same directory (wherever the user
initially saves them by downloading from our website or saving from
email).
About 140 locations will use these files, and each one can initially place
them wherever they want, on their local or network drives, so I cannot fix
the path and force where the files are initially placed. When the main
file
is opened, VBA sets up a subdirectory called 2007 Budget, and creates a
master file. I need to MOVE the other two files into this subdiretory as
part
of the set up process so they are in the same subfolder. I just need to go
up
one directory from the 2007 Budget directory and move these files down to
the
2007 Budget directory. Can anyone help? Thanks!