my goal is to move specified folders and their contents outof an existing location into a new folder path labeled "Archive". There are about 1000 folders out of 2000 I need moved to this new location. I have a .xlsx file that contains the file paths of each folder that needs moving, listed in column A of the Excel worksheet. I would like my macro to look at the Excel file, read the folder path, move that folder and its contents to a new destination. Repeat through the Excel list until it reaches a blank, then it's considered "Done!"
Here is the code I have found so far (see below). This code will move one folder from one path to another path. I need to enhance this to read each path from my Excel file; I just don't know what that part of the command should look like.
Code and any notes with the code are greatly appreciated! Thank you!
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