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?
 

Some videos you may like

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

carlosanoli

New Member
Joined
Jun 5, 2019
Messages
3
In
Code:
[COLOR=#333333]  Kill DaPasta & xVal[/COLOR]
is actually
Code:
[COLOR=#333333]  Kill FromFolder & xVal[/COLOR]
 

Watch MrExcel Video

Forum statistics

Threads
1,098,991
Messages
5,465,863
Members
406,451
Latest member
KARANDREA

This Week's Hot Topics

Top