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

find all .dot that have a particular bookmark 1

Status
Not open for further replies.

keenanbr

Programmer
Oct 3, 2001
469
IE
I need to amend all templates (.dot files) that have a particular bookmark. Is there any way to search for a bookmark. I just want a listing of all files that have this bookmark.

Thanks in advance
 
Well sure it can be done. You will have to open each file though.

What have you tried so far? You can record a macro looking for the bookmark. Then take that code and loop through all the documents. There are a couple of ways to do that looping (using Dir, or using FileSystemObject).

Are all the files in the same folder? If they are, then Dir would work fine. If you have to do a bunch of search not just of files, but of folders as well, you may want to use FileSystemObject. As you mention .DOT files, they are likely to be in only a few folders...I hope. Here is code that looks in .DOC files for a bookmark ("findme") is a specific folder. Just change the folder path to where your DOT files are, and change the *.doc to *.dot.
Code:
Sub ListDocWithBookmark()
Dim oFile
Dim strPath As String
Dim msg As String
strPath = "C:\test\test2\"
oFile = Dir(strPath & "*.doc")
Do While oFile <> ""
    Documents.Open FileName:=strPath & oFile
    If ActiveDocument.Bookmarks.Exists("findme") = True Then
        msg = msg & oFile & vbCrLf
    End If
    Documents(oFile).Close
    oFile = Dir
Loop
MsgBox "The following document(s) have the Bookmark ""findme"" " & _
    vbCrLf & msg
End Sub
You could of course use this in conjunction to your "amending" of the .DOT files.

Gerry
 
thanks, but tried this code and get 'Object required' on 'Documents.Open FileName:=strPath & oFile'. Am I missing something?

Regards,
 
You ARE running this from Word, yes?

You HAVE changed the variables, yes?

If you step through it, what are the values for strPath, and oFile when you get the error?

Gerry
 
Sorry, I was tryingbto run it from VB. Ran it from word and it worked a treat. Much thanks
 
Ah. You can run it using VB, you just need the proper instance of Word.

Gerry
 
Is it possible to do the same thing with a MergeField.

Thanks in advance
 
Yes, but you may have to play around a bit. Will answer in other thread.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top