2
我有一列文件在2列A
和B
。VBA复制文件它它不存在
A
列是源的乙B
列是目的地
下面复制文件的代码从源到目的地。但是,如果目的地存在,它会给我错误。有什么条件,如果它发现它存在,它不会做任何?
代码有什么问题?
Sub FC_Copy()
Dim ClientsFolderDestination
Dim fso As New FileSystemObject
Dim rep_destination
Dim source
lastrow = ThisWorkbook.Worksheets("XClients").Cells(Application.Rows.Count, 1).End(xlUp).Row
For i = 5 To lastrow
source = ThisWorkbook.Worksheets("XClients").Cells(i, 1).Value
ClientsFolderDestination= ThisWorkbook.Worksheets("XClients").Cells(i, 2).Value
If fso.FileExists(source) Then
rep_destination = Left(ClientsFolderDestination, Len(ClientsFolderDestination) - Len(fso.GetFileName(ClientsFolderDestination)) - 1)
If Not fso.FolderExists(rep_destination) Then
sub_rep = Split(rep_destination, "\")
myrep = sub_rep(0)
If Not fso.FolderExists(myrep) Then
MkDir myrep
End If
For irep = 1 To UBound(sub_rep)
myrep = myrep & "\" & sub_rep(irep)
If Not fso.FolderExists(myrep) Then
MkDir myrep
End If
Next
End If
fso.CopyFile source, ClientsFolderDestination
End If
Next i
end sub
什么是'iRow'?什么是“目的地”? –
@SiddharthRout我编辑代码 – JeanLo
最后一个问题,您在col A和col B中有什么价值?在此输入。有一个更简单的方法来做到这一点 –