mscallisto
Technical User
I'm trying to identify all Media type files (.avi .mov etc)
from any mapped drive on a file share e.g. (H
1st parameter in call on code line 16
and including its sub folders (True) 3rd parameter in call on code line 16
example: GetFilesInFolders "H:", "*.*", True, True
While cycling thru all the subfolders (code lines 51 - 54)
I get an error that sends me to (code lines 6 - 9)
I expected the Resume Next (on line 9) would bring me back to Next SubFolder (on line 54)
but instead it sends me to Line 16.
Even after reading the "Help on Resume Next" I don't understand why nor can I see a way to make it work.
from any mapped drive on a file share e.g. (H
and including its sub folders (True) 3rd parameter in call on code line 16
example: GetFilesInFolders "H:", "*.*", True, True
While cycling thru all the subfolders (code lines 51 - 54)
I get an error that sends me to (code lines 6 - 9)
I expected the Resume Next (on line 9) would bring me back to Next SubFolder (on line 54)
but instead it sends me to Line 16.
Even after reading the "Help on Resume Next" I don't understand why nor can I see a way to make it work.
Code:
1 Dim ErrorResult As String, Pathname As String
2 Sub IsolateFileTypes()
3 On Error GoTo MyProcedure_Error
4 GoTo MyProcedure_Exit
5 MyProcedure_Error:
6 If Err.Number = 70 Then
7 MsgBox ("You probably don't have permissions to access this folder ")
8 ErrorResult = "Access Denied"
9 Resume Next
10 Else
11 ErrorResult = "Some Other Reason"
12 Resume Next
13 End If
14 MyProcedure_Exit:
15 ' startpoint, filter, search sub folders, first-time-switch
16 GetFilesInFolders "H:", "*.*", True, True
17 ActiveWorkbook.Save
18 MsgBox ("Done")
19 End Sub
20 Sub GetFilesInFolders(SourceFolderName As String, FileExtensions As String, IncludeSubFolders As Boolean, FirstTime As Boolean)
21 Dim FSO
22 Dim SourceFolder, SubFolder
23 Dim FileItem
24 Dim r As Long
25 Dim strFileName As String, strSearchItem As String, strVlookupResults As Variant
26 Dim intLastRow As Integer, intCounter As Integer
27 Dim strFiletype As Range
28 Set FSO = CreateObject("Scripting.FileSystemObject")
29 Set SourceFolder = FSO.GetFolder(SourceFolderName)
30 intLastRow = Worksheets("Extensions").UsedRange.SpecialCells(xlCellTypeLastCell).Row
31 Set strFiletype = Worksheets("Extensions").Range("A1:B" & intLastRow)
32 If FirstTime Then
33 intCounter = 4
34 FirstTime = False
35 End If
36 r = Range("A65536").End(xlUp).Row + 1
37 i = i + 1
38 For Each FileItem In SourceFolder.Files
39 strSearchItem = Right(FileItem.Name, 3)
40 strVlookupResults = Application.VLookup(strSearchItem, strFiletype, 2, False)
41 If (Not IsError(strVlookupResults)) Then
42 Worksheets("MediaFound").Cells(r, 2) = FileItem.Name
43 Worksheets("MediaFound").Cells(r, 3) = strVlookupResults
44 Cells(r, 1).Formula = FileItem.Path
45 Cells(r, 4).Formula = FileItem.Size
46 r = r + 1 ' next row number
47 intCounter = intCounter + 1
48 End If
49 Next FileItem
50 If IncludeSubFolders Then
51 For Each SubFolder In SourceFolder.SubFolders
52 Application.StatusBar = SubFolder
53 GetFilesInFolders SubFolder.Path, FileExtensions, True, False
54 Next SubFolder
55 End If
56 End Sub