Hi Vincent
In VBA you can use something like this:
Dim oDoc As Word.Document
Dim bm As Word.Bookmark
Set oDoc = Word.ActiveDocument
For Each bm In oDoc.Bookmarks
Debug.Print bm.Name
Next bm
I'll leave you to translate to C#.
You might like to know that Word accumulates hidden bookmarks as it goes
about its work. And a user or developer might have created a hidden
bookmark. You can see them at Insert > Bookmark, by ticking the hidden
bookmarks box.
If you only want to show the unhidden bookmarks, try something like this:
Dim oDoc As Word.Document
Dim bm As Word.Bookmark
Dim bWasHiddenBookmarks as Boolean
Set oDoc = ActiveDocument
bWasHiddenBookmarks = oDoc.Bookmarks.ShowHidden
oDoc.Bookmarks.ShowHidden = False
For Each bm In oDoc.Bookmarks
Debug.Print bm.Name
Next bm
oDoc.Bookmarks.ShowHidden = bWasHiddenBookmarks
Hope this helps.
Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
> How to get all the bookmark names in a word file in C#
> Many thanks for your replying.
vincent - 20 Aug 2007 09:50 GMT
Wow!
It is pretty cool.
Thank you very much.
"Shauna Kelly" 來函:
> Hi Vincent
>
[quoted text clipped - 40 lines]
> > How to get all the bookmark names in a word file in C#
> > Many thanks for your replying.