VBA Copy in folder and sub folder faster

roykana

Active Member
Joined
Mar 8, 2018
Messages
311
Office Version
  1. 2010
Platform
  1. Windows
Dear All master,


I want the vba code to copy over entire folders and sub folders very fast.

The vba code below can only be in one folder so if there is, I can modify the vba code to my liking and also I want the process to be very fast.


Thanks

roykana
VBA Code:
Sub copyfiles()

'Updateby royKana

Dim xRg As Range, xCell As Range

Dim xSFileDlg As FileDialog, xDFileDlg As FileDialog

Dim xSPathStr As Variant, xDPathStr As Variant

Dim xVal As String

On Error Resume Next

Set xRg = Application.InputBox("Please select the file names:", "roykana", ActiveWindow.RangeSelection.Address, , , , , 8)

If xRg Is Nothing Then Exit Sub

Set xSFileDlg = Application.FileDialog(msoFileDialogFolderPicker)

xSFileDlg.Title = "Please select the original folder:"

If xSFileDlg.Show <> -1 Then Exit Sub

xSPathStr = xSFileDlg.SelectedItems.Item(1) & "\"

Set xDFileDlg = Application.FileDialog(msoFileDialogFolderPicker)

xDFileDlg.Title = "Please select the destination folder:"

If xDFileDlg.Show <> -1 Then Exit Sub

xDPathStr = xDFileDlg.SelectedItems.Item(1) & "\"

For Each xCell In xRg

xVal = xCell.Value

If TypeName(xVal) = "String" And xVal <> "" Then

FileCopy xSPathStr & xVal, xDPathStr & xVal

End If

Next

End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Dear all master,
can anyone help me for the vba code?

Thanks
Roykana
 
Upvote 0
Dear all master,
can anyone help me for the vba code?

Thanks
Roykana
 
Upvote 0
Dear all master,
can anyone help me for the vba code?

Thanks
Roykana
 
Upvote 0
Dear all master,
can anyone help me for the vba code?

Thanks
Roykana
 
Upvote 0
Dear all master,
can anyone help me for the vba code?

Thanks
Roykana
 
Upvote 0
Dear all master,

can anyone help and provide a solution for the vba code?


thank you

Roykana
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,159
Members
453,021
Latest member
Justyna P

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