Macro to Copy Files from one directory to another directory.

abhay_547

Board Regular
Joined
Sep 12, 2009
Messages
179
Hi All,
I have below macro which creates a new directory on a network drive and then copies some files to the same directory. The directory name is as different every day as it also has date in it's name. I am able to create a new directory every day using the below macro but it doesn't allow me to copy the files from a different directory to the new created directory. Please help.
Code:
Sub RunDownloadTool()
Dim filePath As String
Dim foldername As String
filePath = "[URL="file://\\OCS\Datadump\Daily\"]\\OCS\Datadump\Daily\[/URL]"
foldername = ThisWorkbook.Worksheets("Sheet1").Range("B1").Value
MkDir (filePath & foldername)
FileCopy "[URL="file://\\OCS\Datadump\Daily\REGO\AML.bat"]\\OCS\Datadump\Daily\REGO\AML.bat[/URL]", "[URL="file://\\OCS\Datadump\Daily\"]\\OCS\Datadump\Daily\[/URL]" & foldername & "\" & AML.bat
End Sub
The Above macro gets stuck on the FileCopy Line.
Thanks a lot for your help in advance.:)
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Are you sure you are getting the filepaths correct?

Try this, it might not work but it should help you locate the problem.:)
Rich (BB code):
Sub RunDownloadTool()
Dim strNewFldr As String
Dim strOldPath As String
Dim strNewPath As String
Dim strFileName As String
 
    strOldPath = "\\OCS\Datadump\Daily\"
 
    strNewFldr ThisWorkbook.Worksheets("Sheet1").Range("B1").Value
 
    strNewPath = strOldPath & strNewFldr
 
    strFileName = "AML.bat"
 
    MkDir strNewPath
 
    FileCopy strOldPath & "\" & strFileName, strNewPath & "\" & strFileName
 
End Sub
 
Upvote 0
Hi Norie,

Thanks a lot for your reply, I am trying to run the batch file in the same macro but it's not working. Below is the code line which I have added to the same before end sub.

Code:
Shell (strNewPath) & "\" & AML.bat

Thanks a lot for your help in advance.:)
 
Upvote 0
So the copy is working but now you can't run the batch (.bat) file?
 
Upvote 0
Hi Norie,

Yes, I am unable to run the batch file. Do you want to put this question in a new thread ?.

Thanks a lot for your help in advance.:)
 
Upvote 0
May as well stick to this one for the now.

How isn't the file running?

Is it not being found? eg it hasn't been copied to the correct location
 
Upvote 0
Hi Norie,

Thanks a lot for your reply, I have also not sure what is happening because I can run the batch file from cmd but it doesn't run when I try to execute the same using my excel macro. It's very strange..
I have checked the path and it's correct.

Thanks a lot for your help in advance.:)
 
Upvote 0
When you run it from the command line do you know which folder/path you are actually runnint it from?

It could be running from a completely different location than the one you are trying to run it from with the Shell.

Have you double checked the file is being copied to where you want it?

Perhaps you could navigate to that location using the command line and then check what files are there.
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,255
Members
449,075
Latest member
staticfluids

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