View Full Version : Solved: XCOPY Command Using VBA?
Wolfgang
02-01-2007, 04:58 AM
Gentlemen,
Can the following DOS command be executed using VBA?
XCOPY E:\MY-TOOLS\*.* C:\MY-XLS-BACKUP /E /D:01-31-2007
Thank you...
Best,
Wolfgang
CCkfm2000
02-01-2007, 05:24 AM
try using the command shell
e.g
Sub test()
Shell "xcopy m:\0\*.* m:\1\*.*"
End Sub
hope this helps
Bob Phillips
02-01-2007, 05:27 AM
This worked for me
retval = Shell("XCOPY C:\TestFolders\*.* C:\TestBackup /E", 0)
Wolfgang
02-01-2007, 05:45 AM
Gentlemen...
Thank you both for your replies...but as far as I can see (tell), nothing was copied...
Bob, I adjusted your folder names according to mine without any results...
I'm running US-Office 2003 Pro SP2 on Windows XP Home...
Best,
Wolfgang
Bob Phillips
02-01-2007, 08:01 AM
Don't know what to say Wolfgang. I tried it and it worked here.
Wolfgang
02-01-2007, 08:07 AM
Bob, I'm using this line of code and it does not do anything at all:
retval = Shell("XCOPY E:\MY-TOOLS\*.* C:\MY-XLS-BACKUPS /E", 0)
Best,
Wolfgang
Bob Phillips
02-01-2007, 08:14 AM
One thing I forgot to mention, it didn't work if TestBackup didn't exist. I tried again and it worked.
You can create the directory like so
On Error Resume Next
MkDir 'C:\TestBackup"
On Error Goto 0
CCkfm2000
02-01-2007, 08:14 AM
this works for me
Sub test()
Shell "XCOPY m:\MY-TOOLS\*.* m:\MY-XLS-BACKUPS\*.* /E"
End Sub
Wolfgang
02-01-2007, 08:24 AM
Gentlemen,
Both solutions work now...
Can you also incorporate the DOS parameter below as well, please!
/D:01-31-2007
Best,
Wolfgang
Bob Phillips
02-01-2007, 08:26 AM
I don't know what that one does, but wouldn't you just string it on the end?
Wolfgang
02-01-2007, 08:30 AM
Bob...
I just did that:
XCOPY E:\MY-TOOLS\*.* C:\MY-XLS-BACKUP /E /D:01-31-2007
It only copies files having the date specified and above...
It works now...
Have a nice day, both of you...
Best,
Wolfgang
mdmackillop
02-02-2007, 03:28 PM
You could add the date into the code, say for the last 7 days
Sub test()
Dim str As String
str = "XCOPY m:\MY-TOOLS\*.* m:\MY-XLS-BACKUPS\*.* /E /D:" & Format(Date - 7, "mm-dd-yyyy")
Shell str
End Sub
Wolfgang
02-03-2007, 01:21 AM
Good Morning Malcolm,
Thank you very much for your solution, too...
Now I got three tools to choose from...one for every day in the week...
Have a nice weekend,
Wolfgang
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.