shell roboCopy 'not recognized as internal or external command, operable program or batch file' error

john316swan

Board Regular
Joined
Oct 13, 2016
Messages
66
Office Version
  1. 2019
Platform
  1. Windows
I am looping through a connection to sync folders from a network drive onto a google drive and I can't figure out why cmd is giving me:
'robocopy' is not recognized as an internal or external command, operable program or batch file." error

Here is my code:
VBA Code:
'Here we can run the batch files to ROBOCOPY athletic offer letters to coaches
For Each item In ath
    sourceCopy = """X:\Financial Aid – Athletics\2020-2021 Offer Letter & CW\" & item & """"
    RoboCopy = """G:\My Drive\AthleticOfferLetter\" & item & "\2020-2021" & """"
    shellCommand = "cmd /c robocopy " & sourceCopy & " " & RoboCopy & " /XO"
   Call Shell(shellCommand, vbMaximizedFocus)
Next item

When I run the command line without the vba loop, it successfully copies those folders, but can't get the vba shell command to work properly. Thanks for your help!

@DanteAmor haha, since you usually are able to help, just tagging you up front ;)
 
Last edited:

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
*I am looping through a collection not connection just in case someone starts wondering.

When I debug.print the sourceCopy & RoboCopy & " /XO" in the immediate window, I can copy that string and manually run a command line robocopy and it works, but can't get the code to work.
 
Upvote 0
I was determined to fix it quickly, but I had a meeting...finally solved it on my own :) yay me.

VBA Code:
'Here we can run the batch files to ROBOCOPY athletic offer letters to coaches
For Each item In ath
    sourceCopy = """X:\Financial Aid – Athletics\2020-2021 Offer Letter & CW\" & item & """"
    RoboCopy = """G:\My Drive\AthleticOfferLetter\" & item & "\2020-2021" & """"
    shellCommand = "cmd /c cd ""C:\Windows\System32"" && robocopy " & sourceCopy & " " & RoboCopy & " /XO"
   Call Shell(shellCommand, vbMaximizedFocus)
Next item

I had to change the directory to where roboCopy was stored in my system (cd ""C:\Windows\System32") before I ran robocopy and then I figured out how to separate shell commands using "&&" before I ran robocopy.
 
Upvote 0
Solution

Forum statistics

Threads
1,216,015
Messages
6,128,296
Members
449,437
Latest member
Raj9505

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