Hi Experts,
I'm attempting to Copy a multiple list of folders and all the contents within them (Subfolders and Files) that are listed in column A to the new location list in column B. I've attempted using the code below but I'm getting the Run-time error '91' Object variable or with block variable not set at the folder line near the bottom.
Any help would be greatly appreciated as this would really save me a lot of time.![]()
Sub CopyFolders() Dim Cell As Range Dim oFolder As Object Dim oShell As Object Dim Rng As Range Dim RngEnd As Range Dim Wks As Worksheet Set Wks = ActiveSheet Set Rng = Wks.Range("A1") Set RngEnd = Wks.Cells(Rows.Count, Rng.Column).End(xlUp) Set Rng = IIf(RngEnd.Row < Rng.Row, Rng, Wks.Range(Rng, RngEnd)) Set oShell = CreateObject("Shell.Application") For Each Cell In Rng Set oFolder = oShell.Namespace(Cell.Offset(0, 1)) ' New folder path in column "B" oFolder.CopyHere Cell ' Copy folder to the new path Next Cell End Sub
Thanks in advance.
Bookmarks