troubleshooting Question

How to fix “Compile error: do without loop”

Avatar of Theva
ThevaFlag for Malaysia asked on
Microsoft Excel
7 Comments1 Solution1287 ViewsLast Modified:
Hi,
I would like to request Experts help. How to fix the mentioned error in the attached script. When I run this script it shows “Compile error: do without loop” at “End Sub”. Hope Expert will help me.

 

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
DataFile.xls
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 7 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”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.

-Mike Kapnisakis, Warner Bros