hey all! I'm hoping for some help adding a line to this code I have.
This current code moves a list of files from a main folder into separate folders that are determined by a spread sheet.
so file 123ana will move into folder titled Ana because the list shows any file with ana goes into folder Ana.
BUT if there is already a file in the folder named 123ana I am getting an error message in my code. this is fine for me, because I know what has happened. but when one of my team mates runs the main macro, this is just a small call macro and they freak out when an error occurs.
I'm hoping to add an "On error resume next" or even a move and keep both command into this macro so the error doesn't show.
any ideas?
all help is greatly appreciated! You guys have taught me so much!!
This current code moves a list of files from a main folder into separate folders that are determined by a spread sheet.
so file 123ana will move into folder titled Ana because the list shows any file with ana goes into folder Ana.
BUT if there is already a file in the folder named 123ana I am getting an error message in my code. this is fine for me, because I know what has happened. but when one of my team mates runs the main macro, this is just a small call macro and they freak out when an error occurs.
I'm hoping to add an "On error resume next" or even a move and keep both command into this macro so the error doesn't show.
any ideas?
all help is greatly appreciated! You guys have taught me so much!!
Code:
Sub xMoveVendorFiles()
Workbooks.Open Filename:= _
"H:\STP Report\Template\Move Vendor Files.xlsm"
Dim d As String, ext As Variant, x As Variant
Dim srcPath As String, destPath As String, srcFile As String
Dim FSO As Object
Dim LR As Long
Dim Rw As Long
Set FSO = CreateObject("scripting.filesystemobject")
With Sheets("Macro")
For Rw = 2 To .Range("A" & Rows.Count).End(xlUp).Row
srcPath = .Range("B" & Rw).Value
destPath = .Range("C" & Rw).Value
ext = Array("*.xls*", "*.pdf")
For Each x In ext
d = Dir(srcPath & x)
Do While d <> ""
If d Like "*" & .Range("A" & Rw).Value & "*" _
And Not d Like "* CK*" Then
srcFile = srcPath & d
FSO.MoveFile srcPath & d, destPath & d
End If
d = Dir
Loop
Next x
Next Rw
End With
Windows("Move Vendor Files").Close savechanges:=False
End Sub