Sub ProcessNewFiles() Dim path As String Dim extension As String Dim prefix As String path = "D:\QA Inbox Active Order\" extension = "xls*" prefix = "AP" Dim file As String file = Dir(path & "*." & extension) 'Loop until we don't have anymore documents in the directory Dim processedPrefix As String processedPrefix = path & prefix Do While file <> "" If (InStr(1, file, prefix) = 0) Then Call Copy_Paste8(path, file) Name (path & file) As (processedPrefix & file) End If file = Dir() Do While file <> "" If (InStr(1, file, prefix) = 0) Then Call Copy_Paste8(path, file) Name (path & file) As (processedPrefix & file) End If file = Dir() DoEvents '<--- Loop ' Register the new execution of the task (1 hour later) Dim newExecution As Date newExecution = Now + TimeValue("01:00:00") ' If new hour is > 17:00, then schedule for next morning at 9:00 Dim newExecutionTime As Date newExecutionTime = newExecution - CLng(newExecution) If (newExecutionTime > TimeValue("17:00:00")) Then newExecution = Day(Now) + 1 + TimeValue("09:00:00") End If Application.OnTime newExecution, "ProcessNewFiles" End Sub
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.
”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.