cortexnotion
Board Regular
- Joined
- Jan 22, 2020
- Messages
- 150
- Office Version
- 2013
- Platform
- Windows
Hi All
I need to loop through the source folder and move all files that don't contain the string to the target folder.
I have read that using "Dir" is the best way to proceed, but would value your help with the code. What I have so far is below.
Many thanks
I need to loop through the source folder and move all files that don't contain the string to the target folder.
I have read that using "Dir" is the best way to proceed, but would value your help with the code. What I have so far is below.
Many thanks
VBA Code:
Sub movefiles()
Dim SourceDir As String, TargetDir As String, Filename As String, LW1 as long
SourceDir = "S:\Test\"
TargetDir = "S:\Test\Completed\"
LW1 = Application.Evaluate("INT((TODAY()-1)/7)*7+1")
Filename = "*WE-" & LW1("dd-mm-yyyy") & "*.xlsx"
Do While (Dir(SourceDir <> ""))
'If SourceDir file does not contain FileName string then move SourceDir file to TargetDir
Loop
End Sub