View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson[_3_] Dave Peterson[_3_] is offline
external usenet poster
 
Posts: 2,824
Default Move Folder Contents

How about:

Option Explicit
Sub testme()

Dim FinalFolderName As String
Dim CurrentFolderName As String

Dim FSO As Scripting.FileSystemObject

Dim FinalFolder As Scripting.Folder
Dim CurrentFolder As Scripting.Folder
Dim myFile As Scripting.File

FinalFolderName = "C:\Closing"
CurrentFolderName = "C:\Assets"

Set FSO = New Scripting.FileSystemObject

If FSO.FolderExists(CurrentFolderName) = False _
Or FSO.FolderExists(FinalFolderName) = False Then
MsgBox "where are they???"
Exit Sub
End If

Set CurrentFolder = FSO.GetFolder(CurrentFolderName)
Set FinalFolder = FSO.GetFolder(FinalFolderName)

For Each myFile In CurrentFolder.Files
myFile.Copy Destination:=FinalFolder.Path & "\" & myFile.Name, _
overwritefiles:=True
myFile.Delete
Next myFile

End Sub

This code requires a reference to the "Microsoft Scripting Runtime"
(tools|References inside the VBE).

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Ryan wrote:

I am trying to set up a way to move files from one folder to another. I found on this board an excellent way to move a file from one folder to another using the "Name" function, but this doesn't exactly work for my situation. I am not going to know the name of all of the files in a certain folder, I will only know the folder names. Is there a way to move all of the contents from the "Assets" file to the "Closing" file without just changing the name of the file?

Ryan


--

Dave Peterson