Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

searching for a word in the file name

Status
Not open for further replies.

lemonhalls

Technical User
Jun 11, 2004
52
CA
I'm trying to extract all the files in a folder whose file name contains the word "French".

I'm using the following code, but it doesn't pick up the files eg. "treeFrench".

__________________________
Dim lastChar As String
Dim activeDir As String

activeDir = InputBox _
(Prompt:="Enter the path where the files to be merged are stored. ", _
Title:="Path", Default:="U:\SYS\") 'change default as desire

'make a new directory by the name of current month
newDir = activeDir & Format(strPreviousMonth, "mmmm") & "\"
If Dir(newDir, 16) = "" Then MkDir newDir

With Application.FileSearch
.LookIn = activeDir 'folder with files to merge
End With

'move to the end of the document to insert files
Selection.EndKey Unit:=wdStory, Extend:=wdMove

With Application.FileSearch
.NewSearch
.LookIn = activeDir
.SearchSubFolders = False
'searches for files with .doc extension
.FileName = "*.doc"
.TextOrProperty = "French"
.MatchTextExactly = True

'inserting each file one after another
For i = 1 To .FoundFiles.Count
Selection.TypeParagraph
Selection.InsertFile FileName:=.FoundFiles(i), Range:="", _
ConfirmConversions:=False, Link:=False, Attachment:=False

Selection.InsertBreak Type:=wdSectionBreakNextPage
Next i
 
Haven't used that approach before, and don't have time to play. . . but could you use the InStr function? Something along the lines of:

If instr(1, .Filename, "French") Then

Hope that's not way off. . .

VBAjedi [swords]
 
Your search criteria should be adjusted so that you are searching for French in the file name not in the file text/properties:

.FileName = "*French*.doc"
.TextOrProperty = ""
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top