LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
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

 
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
Folder Contents to Excel TC Daniel Excel Discussion (Misc queries) 2 January 23rd 08 05:53 PM
Listing the contents of a folder [email protected] Excel Discussion (Misc queries) 2 April 12th 07 03:54 AM
Macro to remove contents of cell and move all other contents up one row adw223 Excel Discussion (Misc queries) 1 July 1st 05 03:57 PM
When I move scroll bar in excell the contents do not move with it ramneek Excel Discussion (Misc queries) 2 June 29th 05 07:35 PM
Move file to different folder Don Guillett[_4_] Excel Programming 4 August 29th 03 07:35 PM


All times are GMT +1. The time now is 07:28 AM.

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"