Recursive directory search- syntax question

K

Ker_01

I've tried to adapt some old code to recursively check for word files in the
target directory so I can open each one and inspect the contents with VBA
(per my previous post). Unfortunately, the following code appears to hang on
the .execute command. Right now, the test directory has about 50 files and
no subdirectories. CPU and network access are nominal, so AFAIK this doesn't
appear to be a situation where it is just taking forever to execute
(although I welcome suggestions on how to know for sure).

Is my syntax wrong, or can anyone suggest alternative troubleshooting?

Thanks,
Keith


Sub FindAllTxtFiles() 'finds all .doc files in the target directory

DirPath = "\\networkdrive\test" 'also tried with a trailing "\"
just in case it needed one

With Application.FileSearch
.NewSearch
.LookIn = DirPath 'selected directory
.SearchSubFolders = True
.FileName = "*.doc"
If .Execute > 0 Then '*** stops here ***
For i = 1 To .FoundFiles.Count
'Do my file processing here
MsgBox FileName
Next i
End If
End With

End Sub
 
K

Karl E. Peterson

I have no idea why the object model may be breaking down here. But if you'd like to
do a "pure VB(A)" recursive search, see http://vb.mvps.org/samples/DirDrill for a
drop-in ready class module. Black boxes are *always* better when they're
transparent! :)
 
D

Doug Robbins - Word MVP

I had intended the counters only to be used for the tables and the rows
within them.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top