0

I've been looking around for a solution to this for a little while now.

I need to extract all bookmarks from a word document so I can manipulate them as I please. So I guess I just need a reference to them rather than the actual bookmarks.

What I've found so far is just solutions where you need to search for names of the bookmarks but I just want to get references to all the bookmarks. I might not know their names at all times. I thought that I could get the bookmarks by calling MyDocument.Bookmarks but so far I still haven't figured out how to work that property.

If I extract the bookmarks from a template, the names won't change. But if I take the bookmarks from an unknown document, I have no idea how to get the references.

Any help?

OmniOwl
  • 5,477
  • 17
  • 67
  • 116
  • I didn't understand, you have a collection of bookmarks. You can get their name through the Name property. You can replace it with content, to move it, to delete it...what's missing? – Adriano Repetti May 14 '13 at 08:13
  • @Adriano I don't understand how to get all bookmarks in a document and then manipulate them through C#. The documentation have not been of help so far. – OmniOwl May 14 '13 at 08:14
  • 1
    From VBA you can easily get all bookmarks using collection (which you mentioned) `Document.Bookmarks`. To get them all you could run simple loop like this (VBA codding): `For Each BM in MyDocument.Bookmarks`... what you are missing to run something like this in C#. Do you get any exception? – Kazimierz Jawor May 14 '13 at 08:22
  • @KazJaw I just tried that now finally. In C# that is. Thank you KazJaw that got me all the bookmarks. – OmniOwl May 14 '13 at 08:23

1 Answers1

6
foreach (Bookmark bookmark in document.Bookmarks)
{
    // Do whatever you want with the bookmark.
}
cremor
  • 6,669
  • 1
  • 29
  • 72