Copy a file from a folder to another

carlosanoli

New Member
Joined
Jun 5, 2019
Messages
3
Hello Guys!!

I am trying to code in VBA to copy a file from a folder to another.
My idea is to click the button, than select multiple files name in cells range.
FromFolder would be a Folder that won't change, so i put the folder path (this folder is located in a network).
The ToFolder is a folder that each user has in your own computer, so before click the button the user needs to put the folder path destination in Cell "A1".

:
Code:
Private Sub CommandButton1_Click()Dim FSO As Object
Dim FromFolder As String
Dim ToFolder As Variant
Dim NomeBase As Range
Dim ConjBase As Range
Dim xVal As String




Set NomeBase = Application.InputBox("Selecione as bases:", "Selecione as Bases", ActiveWindow.RangeSelection.Address, , , , , 8)
    If NomeBase Is Nothing Then Exit Sub
    
    FromFolder = "C:\Users\carlossantana.CARLOS\Downloads"
    
    ToFolder = Range("A1").Value
    
For Each ConjBase In NomeBase
        xVal = NomeBase.Value
        If TypeName(xVal) = "String" And xVal <> "" Then
            FileCopy FromFolder & xVal, ToFolder & xVal
            Kill DaPasta & xVal
        End If
    Next
End Sub

When I run the code, the error 53 appears.
Does Anyone can help me figured out what is happening?
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
In
Code:
[COLOR=#333333]  Kill DaPasta & xVal[/COLOR]
is actually
Code:
[COLOR=#333333]  Kill FromFolder & xVal[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,214,942
Messages
6,122,366
Members
449,080
Latest member
Armadillos

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