VBA shell command fails unless manually stepped through
Posted on 2011-10-30
This Visual Basic for Applications code is part of a longer subroutine. Interestingly, the code works just fine on one of the 2 computers that I am trying to use it on.
On the failure box, the xcopy fails if the subroutine is allowed to run, or if a breakpoint is placed just before the bold line, and then you press F5 after it breaks.
If you wait for the break and press F8 to step through the bold line, the xcopy succeeds.
I considered a number of differences between the 2 boxes, including the failure one having less RAM (didn't fix it), whether the various drives referred to by Y:\ or C:\ were local or on the LAN (didn't fix it), whether the various drives were in "Trusted Zones" (didn't fix it). I also tried putting a pause using Application.OnTime Now()+ 30 seconds or so (didn't fix it).
Also, the computers are plugged in and powered on, ha ha.
DrivieLetter = "Y"
On Error Resume Next
XRayDestinationFolder = DrivieLetter & ":\StoreToMove\" & XRaySourceFolder
ChDir "C:\Genesis Digital Imaging\Omni-Vue\Image\"
XRaySourceFolder = "C:\Genesis Digital Imaging\Omni-Vue\Image\" & XRaySourceFolder
Set fs = CreateObject("Scripting.FileSystemObject")
fs.CopyFolder XRaySourceFolder, XRayDestinationFolder
Shell "xcopy Y:\StoreToMove Y:\Roentgen\Xrays\XrayImages /e"