add Error Resume to current code

AnnieLox

New Member
Joined
Sep 18, 2017
Messages
22
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!!


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
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Try adding to code:
Rich (BB code):
On Error Resume Next
FSO.MoveFile srcPath & d, destPath & d
On Error Goto 0
 
Upvote 0
Thank you so much for your help with this! it worked perfect. I new it could be simple enough, I just didn't know where to put it.
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,164
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top