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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

search templates for text 1

Status
Not open for further replies.

keenanbr

Programmer
Oct 3, 2001
469
IE
I imagine this is fairly straight foreward but I don't know how to do it. I want to search through all templates (.dot) for a specific piece of text.

Thanks in advance,

Brian
 
keenanbr,
You can use the [tt]FileSearch[/tt] object. Here is an example from a Word (2000) macro that checks the C drive and subfolders for Office Templates that contain "Your test" and displays a message box with the results.
Code:
Sub DOT_Text_Search()
Dim MyFileSearch As FileSearch
Dim MyFoundFile As Variant
Dim MyFoundFiles As String

Set MyFileSearch = Application.FileSearch

With MyFileSearch
  .NewSearch
  .LookIn = "C:\"
  'Be careful using this with the root drive
  .SearchSubFolders = True
  .FileType = msoFileTypeTemplates
  .TextOrProperty = "[i]Your test[/i]"
  .MatchTextExactly = True
  .Execute
End With

For Each MyFoundFile In MyFileSearch.FoundFiles
  MyFoundFiles = MyFoundFiles & vbCrLf & MyFoundFile
Next MyFoundFile
MsgBox MyFoundFiles, vbOKOnly, "Files Found"

Clean_up:
Set MyFileSearch = Nothing

End Sub

Hope this helps,
CMP

(GMT-07:00) Mountain Time (US & Canada)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top