Robocopy in Excel

andya1981

New Member
Joined
Jun 17, 2010
Messages
1
I am sorting out an archiving strategy for work to move folders from one server to an external hard disk.
I have written a full script in notepad and saved it as a .bat file so i can run it that way.
Can i use excel to state the from and to directory's, and also the file that i wish to exclude from the script.
I'm new to programming so a step by step approach would be good.

This is my .bat file, i have put in the cell numbers of where i want the info to come from.

SET _source=\\FileServ1\e$\users (this in cell A1)

SET _dest=\\FileServ2\e$\BackupUsers (this in cell A2)

SET _what=/move /xd: "\\FileServ1\e$\users\personal" (these folder in cells B1:B100)

SET _options=/R:0 /W:0 /LOG:\\FileServ1\e$\users\MyLogfile.txt


ROBOCOPY %_source% %_dest% %_what% %_options%
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
The easiest way is to use the Shell function to call the Robocopy command with the appropriate parameters. Something like this (untested):

Code:
Sub archive()

    Dim pid As Double
    Dim cell As Range
    Dim source As String, dest As String, what As String, options As String
    
    source = Range("A1").Value & " "
    dest = Range("A2").Value & " "
    options = "/R:0 /W:0 /LOG:\\FileServ1\e$\users\MyLogfile.txt"
    
    For Each cell In Range("B1:B100")
        what = "/move /xd: " & Chr(34) & cell.Value & Chr(34) & " "
        pid = Shell("C:\path\to\Robocopy " & source & dest & what & options, vbNormalFocus)
    Next
        
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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