nour_3d
09-29-2016, 07:17 AM
Hi,
I have list of file names in Sheet 1 ( Main) col C without extn, and against each cell in this col I have the source path of this file listed in Col D, and against each cell I have list of destination which i need to copy this file to and listed in Col E.
so what i need to do is; copy each file from its specific source path to its specific destination path. ex: copy the file named in C1 and its source in D1 to the destination in E1
and so on.
this is the draft of what i tried to do but I am not aware of VBA, I do not know how to make the for loop which count properly
Sub exa() Dim FSO As Object
Dim rCell As Range
Dim Rdir As Range
Dim rngFileNames As Range
Dim FOL_FROM As Range
Dim FOL_TO As Range
Dim i As String
Const EXT As String = ".pdf"
Set rngFileNames = ThisWorkbook.Worksheets("Main").Range("C5:C50")
Set FOL_FROM = ThisWorkbook.Worksheets("Main").Range("D5:50")
Set FOL_TO = ThisWorkbook.Worksheets("Main").Range("E5:E50")
Set FSO = CreateObject("Scripting.FileSystemObject")
i = 1
For Each rCell In rngFileNames
FSO.CopyFile FOL_FROM & rCell.Value & EXT, FOL_TO
i = i + 1
Next
End Sub
I have list of file names in Sheet 1 ( Main) col C without extn, and against each cell in this col I have the source path of this file listed in Col D, and against each cell I have list of destination which i need to copy this file to and listed in Col E.
so what i need to do is; copy each file from its specific source path to its specific destination path. ex: copy the file named in C1 and its source in D1 to the destination in E1
and so on.
this is the draft of what i tried to do but I am not aware of VBA, I do not know how to make the for loop which count properly
Sub exa() Dim FSO As Object
Dim rCell As Range
Dim Rdir As Range
Dim rngFileNames As Range
Dim FOL_FROM As Range
Dim FOL_TO As Range
Dim i As String
Const EXT As String = ".pdf"
Set rngFileNames = ThisWorkbook.Worksheets("Main").Range("C5:C50")
Set FOL_FROM = ThisWorkbook.Worksheets("Main").Range("D5:50")
Set FOL_TO = ThisWorkbook.Worksheets("Main").Range("E5:E50")
Set FSO = CreateObject("Scripting.FileSystemObject")
i = 1
For Each rCell In rngFileNames
FSO.CopyFile FOL_FROM & rCell.Value & EXT, FOL_TO
i = i + 1
Next
End Sub