Good day! Is there a way to modify this code, and not copy files but instead moving them, something like cut from old location and paste to the new location? Many thanks in advance.
Below code was provided more than 10 years ago in another Post thread entitled "VBA code to Copy File Based on Keywords in File Name".
It works great, but I would like to move the files instead of copying them.
Many thanks in advance! Wishing you happy holidays!
Sub CopyFiles_Containing()
Dim sSrcFolder As String, sTgtFolder As String, sFilename As String
Dim c As Range, rPatterns As Range
Dim bBad As Boolean
sSrcFolder = ActiveSheet.Cells(4, 3)
sTgtFolder = ActiveSheet.Cells(5, 3)
Set rPatterns = ActiveSheet.Range("E4:E2000").SpecialCells(xlConstants)
For Each c In rPatterns
sFilename = Dir(sSrcFolder & "*" & c.Text & "*")
If sFilename = "" Then
c.Interior.ColorIndex = 3
bBad = True
Else
While sFilename <> ""
FileCopy sSrcFolder & sFilename, sTgtFolder & sFilename
sFilename = Dir()
Wend
End If
Next c
If bBad Then MsgBox "Some files were not found. " & _
"These were highlighted for your reference."
End Sub
Below code was provided more than 10 years ago in another Post thread entitled "VBA code to Copy File Based on Keywords in File Name".
It works great, but I would like to move the files instead of copying them.
Many thanks in advance! Wishing you happy holidays!
Sub CopyFiles_Containing()
Dim sSrcFolder As String, sTgtFolder As String, sFilename As String
Dim c As Range, rPatterns As Range
Dim bBad As Boolean
sSrcFolder = ActiveSheet.Cells(4, 3)
sTgtFolder = ActiveSheet.Cells(5, 3)
Set rPatterns = ActiveSheet.Range("E4:E2000").SpecialCells(xlConstants)
For Each c In rPatterns
sFilename = Dir(sSrcFolder & "*" & c.Text & "*")
If sFilename = "" Then
c.Interior.ColorIndex = 3
bBad = True
Else
While sFilename <> ""
FileCopy sSrcFolder & sFilename, sTgtFolder & sFilename
sFilename = Dir()
Wend
End If
Next c
If bBad Then MsgBox "Some files were not found. " & _
"These were highlighted for your reference."
End Sub