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".
:
When I run the code, the error 53 appears.
Does Anyone can help me figured out what is happening?
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?