Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / August 2007

Tip: Looking for answers? Try searching our database.

How to get all the bookmark names in a word file in C#

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
vincent - 20 Aug 2007 07:26 GMT
How to get all the bookmark names in a word file in C#
Many thanks for your replying.
Shauna Kelly - 20 Aug 2007 09:35 GMT
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.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.