I have a macro to Cut a and paste workbooks from one folder to another containing "purchase Ledger" ,except the current workbook
When running the macro the Files containing "Purchase Ledger" is not being moved i.e Cut and Pasted
It would be appreciated if someone could amend my code
When running the macro the Files containing "Purchase Ledger" is not being moved i.e Cut and Pasted
It would be appreciated if someone could amend my code
Code:
Sub Move_Files_With_Purchase_Ledger()
Dim sourceFolder As String
Dim destinationFolder As String
Dim fileKeyword As String
Dim fileName As String
Dim fso As Object
sourceFolder = "C:\My Documents"
destinationFolder = "C:\Old My Documents"
fileKeyword = "Purchase Ledger"
' Create the FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
' Iterate through files in the source folder
fileName = Dir(sourceFolder & "\*.*")
Do While fileName <> ""
If InStr(1, fileName, fileKeyword, vbTextCompare) > 0 Then
' Move the file to the destination folder
fso.MoveFile sourceFolder & "\" & fileName, destinationFolder & "\" & fileName
End If
fileName = Dir
Loop
' Clean up the FileSystemObject
Set fso = Nothing
End Sub