Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Searching a Network, file crashes

jbaum

New member
Joined
May 25, 2016
Messages
3
Greetings.
The following is the code that I am using to find a certain file. However, when I run it, the software crashes. I figured out that if I decrease the amount of folders it needs to look through then it works just fine. So my wondering is if there is a way to increase something so that the program will run as many times as it needs to to find the file without crashing the software. I hope that makes sense.


Code:
Option Explicit
Dim jobnumber As String


Sub Main()
        
    jobnumber = InputBox("What is the Job Number")
    FindFile "T:\02 ESTIMATING & SALES\03 JOBS IN PROCESS"


End Sub

Sub FindFile(oFolderStart As String)

Dim ofso As Scripting.FileSystemObject
    Set ofso = CreateObject("Scripting.FileSystemObject")
Dim ofil As Scripting.File
Dim oStartFolder As Scripting.Folder
Dim newfolderpath As String
Dim subfol As Scripting.Folder

     
 newfolderpath = "T:\TempDesignWorksheet"
 Set oStartFolder = ofso.GetFolder(oFolderStart)

    For Each ofil In oStartFolder.Files
        
        If Left(ofso.GetFileName(ofil.Path), 5) = jobnumber And Left(ofso.GetExtensionName(ofil.Path), 2) = "xl" Then
        
        ofil.Copy newfolderpath & "\" & ofil.Name
        
        End If
    
    Next ofil

    For Each subfol In oStartFolder.SubFolders
      FindFile (subfol.Path)
    Next subfol
    
    Set ofso = Nothing
End Sub
 
Top