View Single Post
 
Old 10-15-2014, 09:53 AM
gmaxey gmaxey is offline Windows 7 32bit Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,598
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

It seems that using a procedure similar to your link that the following should work:

Code:
Sub FindPatternMatchedFiles()
Dim oFSO As Object
Dim oRegExp As Object
Dim varFile As Variant
Dim colFiles As Collection
  Set oFSO = CreateObject("Scripting.FileSystemObject")
  Set oRegExp = CreateObject("VBScript.RegExp")
  oRegExp.Pattern = ".*do[ct][mx]"
  oRegExp.IgnoreCase = True
  Set colFiles = New Collection
  RecursiveFileSearch "D:\My Documents\Word\Word Documents\Invoices", oRegExp, colFiles, oFSO
  For Each varFile In colFiles
 
    If Not varFile = "test.docm" Then
      Debug.Print varFile
      'Insert code here to do something with the matched files
    End If
 
  Next
  'Garbage Collection
  Set oFSO = Nothing
  Set oRegExp = Nothing
End Sub
 
Sub RecursiveFileSearch(ByVal strFolder As String, ByRef oRegExp As Object, _
                    ByRef colMatched As Collection, ByRef oFSO As Object)
 
Dim oFolder As Object
Dim oFile As Object
Dim oSubFolder As Object
Dim objSubFolder As Object
  'Get the folder object associated with the target directory
  Set oFolder = oFSO.GetFolder(strFolder)
  'Loop through the files current folder
  For Each oFile In oFolder.Files
    If oRegExp.test(oFile) Then
      colMatched.Add (oFile)
    End If
  Next
  'Loop through the each of the sub folders recursively
  Set oSubFolder = oFolder.Subfolders
  For Each objSubFolder In oSubFolder
    RecursiveFileSearch objSubFolder, oRegExp, colMatched, oFSO
  Next
  Set oFolder = Nothing
  Set oFile = Nothing
  Set oSubFolder = Nothing
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote