I have created a macro in VBA that is supposed to check part numbers on an excel sheet vs the filenames of parts in a file directory. The script is this:
Sub scanDirectory()
Dim path As String
Dim currentPath As String
Dim nameOfFile As String
Dim counterA As Integer
Dim success As Integer
Dim endTester As String
Dim draw As Integer
'put the path to your folder here along with an \
path = "\C:\Users\joe.blow\Documents\"
counterA = 8
Do Until counterA > 4294
nameOfFile = Sheets("Sheet0").Cells(counterA, 2)
currentPath = Dir(path)
success = 0
draw = 0
Do Until currentPath = vbNullString
Debug.Print currentPath
'Success for Model
endTester = nameOfFile + ".SLDPRT"
If currentPath = endTester Then
Sheets("Sheet0").Cells(counterA, 5) = "Y"
success = 1
End If
endTester = nameOfFile + ".sldprt"
If currentPath = endTester Then
Sheets("Sheet0").Cells(counterA, 5) = "Y"
success = 1
End If
'Success for Assembly
endTester = nameOfFile + ".SLDASM"
If currentPath = endTester Then
Sheets("Sheet0").Cells(counterA, 5) = "Y"
success = 1
End If
'Succees for Drawing
endTester = nameOfFile + ".SLDDRW"
If currentPath = endTester Then
Sheets("Sheet0").Cells(counterA, 6) = "Y"
draw = 1
End If
endTester = nameOfFile + ".slddrw"
If currentPath = endTester Then
Sheets("Sheet0").Cells(counterA, 6) = "Y"
draw = 1
End If
If draw = 0 Then
Sheets("Sheet0").Cells(counterA, 6) = "N"
End If
If success = 0 Then
Sheets("Sheet0").Cells(counterA, 5) = "N"
End If
currentPath = Dir()
Loop
counterA = counterA + 1
Loop 'NextLine' End Sub
It works by going line by line and checking each cell vs the entire file tree, checking every permutation of filename extension. It then puts in an empty column if the file is there or not with a corresponding 'Y' or 'N'. It does this with both Models AND Drawings at the same time.
It works great for data sets <100 but my lists are sometimes 9000+ items long. When I run this on those longer sheets, it will run fine for ~5 seconds, then become unresponsive and (Not Responding). If I then wait for a long time >1hr, then it will finish running even though it was "Not Responding". Is there any better way to run this so that it will not take as long or