p2p.wrox.com Forums

Need to download code?

View our list of code downloads.

  Return to Index  

vba_word thread: Re: Listing all bookmarks for each template in a specified directory

Message #1 by patelpm@f... on Fri, 21 Jun 2002 22:17:57
Use document object. set the document using the document path you have. 
Then loop through the ActiveDocument.Bookmarks or objDoc.Bookmarks to get 
list of all bookmarks for the document (where objDoc is the Document 
object that you declared). A skeleton would be ...

Public Sub ReadBookmarks(filePath As String)
    Dim objWord As Word.Application
    Dim objDoc As Document
    Dim iCnt As Integer
    Set objWord = New Word.Application
    Set objDoc = objWord.Documents.Open(filePath, True, False)
    For iCnt = 1 To objDoc.Bookmarks.Count
        Debug.Print objDoc.Bookmarks(iCnt).Name
    Next iCnt
    Set objDoc = Nothing
    Set objWord = Nothing
End Sub


> The following lists all templates in a directory.

> Public Sub PrintAllTemplatesInDirectory()

> Dim MyFile As String
D> im MyPath As String

> MyPath = "C:\WINDOWS\Application Data\Microsoft\Templates\*"
M> yFile = Dir(MyPath & ".dot")

> Do While MyFile <> ""
 >    Selection.TypeText (MyFile) & vbCrLf
 >    MyFile = Dir
L> oop

> End Sub

> How can I extend this to list all the bookmarks for each document in the 
d> irectory?

> Thanks!

> Larry
l> awrence_landis@y...

  Return to Index