Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-15-2014, 09:03 AM
subspace3 subspace3 is offline Macro help regex Windows 7 64bit Macro help regex Office 2010 64bit
Novice
Macro help regex
 
Join Date: Oct 2014
Posts: 8
subspace3 is on a distinguished road
Default Macro help regex

Hi all,

Using bits from

http://vba-tutorial.com/recursive-di...x-file-search/

And bits from another page I've managed to put together a macro that does a recursive search in a path and batch convert word docs to html. When I'm home ill find the code and paste it here to see what you think needs improving.

I'm totally new to this but modifying certain aspects seems like common sense to me.

Anyway, in wanting to not select test.docm in the expression and then process all other documents ending in docx/ docm.
Now for docm/x works ('.*doc[mx]') but the problem is, it includes the macro document itself which is called test.docm.



So it converts that to html, and then closes the active document, this not processing any other documents.

I've tried '(!test.docm) .*doc[mx]' but I'm probably way off.

Any ideas guys?
Reply With Quote
  #2  
Old 10-15-2014, 09:53 AM
gmaxey gmaxey is offline Macro help regex Windows 7 32bit Macro help regex Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
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
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro Needed to bold specific lines and Macro to turn into CSV anewteacher Word VBA 1 05-28-2014 03:59 PM
custom icon, undo/redo for macro, permanent macro Rapier Excel 0 08-05-2013 06:30 AM
Macro help regex Convert RegEx to Word (Devanagari Font Find/Replace) gasyoun Word VBA 9 04-12-2013 04:15 PM
How do I assign a macro to a button when the macro is in my personal workbook? foolios Excel Programming 2 07-27-2011 02:41 PM
Regex in Word: Replaced strings are in disorder chgeiselmann Word 0 04-26-2009 11:33 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:33 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft