macro for moving folders

errtu

Board Regular
Joined
Sep 23, 2010
Messages
134
I have two folders A & B.

I need a macro that will create a new folder C and move all contents from A & B to C.

edit. i forgot, every time it should create a different folder. so that everyday i'll get folder C, D, E, F (maybe name the folders based on date)
 
Last edited:
Alpha Frog,

After I started running the macro over and continuing to test it, I did start to run into some errors. I will copy and paste the code and include the errors in the code with ' marks.

Sub CopyFile1()

Dim FromPath As String, ToPath As String
Dim i As Long

If MsgBox("Are you sure you want to move all stale files?", vbYesNo) <> vbYes Then Exit Sub

For i = 1 To Cells(Rows.Count, "A").End(xlUp).Row

If Len(Dir((Cells(i, "C").Value & "\Stale Files"), vbDirectory)) = 0 Then
MkDir Cells(i, "C").Value & "\Stale Files"
End If

FromPath = Cells(i, "D").Value
ToPath = Cells(i, "C").Value & "\Stale Files\" & Cells(i, "B").Value
'FileCopy Source:=FromPath, Destination:=ToPath <<<Error "Permission Denied"
'CreateObject("Scripting.FileSystemObject").CopyFile FromPath, ToPath <<<Error"Permission Denied"
'Name FromPath As ToPath <<<worked but created a new file and didn't keep the old one


Next i

End Sub

If you have any advice to fix the errors, or make a copy of the initial file and name the second file. Please let me know, thanks for your help!
 
Upvote 0

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
I realized, as an intern, that I don't have access to certain folders. Thanks for your help! It seems to work great.
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,903
Members
452,948
Latest member
Dupuhini

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