VBA to move specified folders and their contents to a different folder

thummel1

New Member
Joined
Nov 1, 2010
Messages
4
I need to create VBA that will read from an Excel file, the list of about 998 file paths to folders. The file paths to the folders appear in column A. There are about 998 folder paths. Then, I need to move those folders, their subfolders and all their contents to a different folder here: Q:\Corporate-Shares\Corp\SHAREDIR\HR Technology\Data Analyst\Cyclical Reports\FPR\Archive.

I could achieve this if I manually dragged each folder, one by one (or ctrl+click) to the file path destination above, but I'm not about to do that for 998 folders, and there are about 1000 other folders that need to stay in there.

I am finding a ton of VBA that moves Excel files, but I'm interested in moving folders (whose paths are saved on an Excel spreadsheet) and their contents.

Thank you!
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
This might be a good starting point.

Copy and Move files and folders

Thank you for these examples. I've combed through several, and they appear to move or copy the .xlsx files from their current location to a new location and leave the folder where it was, but I need the entire folder, as well as the sub-folders and the contents in each of those subfolders moved. That's the part of the VBA I can't seem to get my hands on. The additional piece I need is to be able to paste into the code appx 1000 folder paths, with the assumption that the macro will read each folder path, move it to the Archive folder, then move the next folder path to the archive folder, and so on.
 
Upvote 0
Hi, I was able to find a macro that does move one folder, its subfolders and contents (see below). Now I need to modify this so that it will do one of 2 things:
1) I can either paste 1000 files paths into this code so it will loop through each folder and move it, or
2) Have the macro point to my Excel file that contains all the folder paths in column A of the file and move them that way.

I'm such a beginner when it comes VBA code. If anyone know how to do this and can provide the code as well as notes as to what each command does so I can get familiar with simple command options, I would greatly appreciate it!
Sub Move_Rename_Folder()
'This example move the folder from FromPath to ToPath.
Dim fso As Object
Dim FromPath As String
Dim ToPath As String
FromPath = "Q:\Corporate-Shares\...\Test folder 1" '<< Change
ToPath = "Q:\Corporate-Shares\...\Test Archive Folder" '<< Change
'Note: It is not possible to use a folder that exist in ToPath
If Right(FromPath, 1) = "\" Then
FromPath = Left(FromPath, Len(FromPath) - 1)
End If
If Right(ToPath, 1) = "\" Then
ToPath = Left(ToPath, Len(ToPath) - 1)
End If
Set fso = CreateObject("scripting.filesystemobject")
If fso.FolderExists(FromPath) = False Then
MsgBox FromPath & " doesn't exist"
Exit Sub
End If
If fso.FolderExists(ToPath) = True Then
MsgBox ToPath & " exist, not possible to move to a existing folder"
Exit Sub
End If
fso.MoveFolder Source:=FromPath, Destination:=ToPath
MsgBox "The folder is moved from " & FromPath & " to " & ToPath
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,461
Messages
6,124,955
Members
449,199
Latest member
Riley Johnson

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top