Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Silver Lounger
    Join Date
    Jan 2001
    Location
    West Long Branch, New Jersey, USA
    Posts
    1,921
    Thanks
    6
    Thanked 9 Times in 7 Posts

    Bookmark rpt (2003)

    Hi All,

    I'm looking for functionality (VBA, add-in, ...?) that will give me information about bookmarks in a document. The info I'd be looking for is:
    - bookmark name (rqd)
    - some precise specification of where the bookmark was defined: at least a page# for those bookmarks that only specify a location but more precise location identification would be better; for those bookmarks that define a range, the page#(s) or text values of the range (rqd to have something but somewhat flexible on what is provided here)
    - some precise specification of the location(s) where the bookmark is referenced - precise specification should be at least the page # but para or surrounding text would be better (rqd)
    - the type of reference - is the ref to the bookmark's page #, text, etc (real nice to have)

    Didn't see anything on the lounge that came close. Anyone know of anything?

    TIA

    Fred

  2. #2
    3 Star Lounger
    Join Date
    Apr 2004
    Location
    Boston, Massachusetts, USA
    Posts
    389
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Bookmark rpt (2003)

    Hi Fred,

    I've not heard of anything like that, but you piqued my interest. The following is a rough attempt at most of the functionality you asked for. The collection colBkData contains all the data you're looking for. For this example, I just dump it out into a new document, but you could of course put it in a table, or otherwise format it.

    <pre>Sub GetBookmarkInfo()
    Dim bk As Bookmark
    Dim colBkData As Collection
    Dim col As Collection
    Dim colRefs As Collection
    Dim doc As Document
    Dim strOutput As String
    Dim k As Long
    Dim docReport As Document

    Set colBkData = New Collection
    Set doc = ActiveDocument
    doc.Bookmarks.ShowHidden = True

    For Each bk In doc.Bookmarks
    Set col = New Collection
    col.Add Key:="name", Item:=bk.Name
    col.Add Key:="page", Item:=bk.Range.Information(wdActiveEndPageNumber)
    col.Add Key:="para-text", Item:=bk.Range.Paragraphs(1).Range.Text
    Set colRefs = FindRefsToBookmark(bk)
    col.Add Key:="refs", Item:=colRefs
    colBkData.Add Item:=col
    Set col = Nothing
    Next bk
    Dim j As Integer
    For k = 1 To colBkData.count
    strOutput = strOutput & _
    "Bookmark Name: " & colBkData(k)("name") & vbCr & _
    "Appears on page: " & colBkData(k)("page") & vbCr & _
    "Surrounding text: " & colBkData(k)("para-text") & vbCr
    If Not colBkData(k)("refs") Is Nothing Then
    For j = 1 To colBkData(k)("refs").count
    strOutput = strOutput & _
    "Referenced on page: " & colBkData(k)("refs")(j)("page") & vbCr & _
    "In the text: " & colBkData(k)("refs")(j)("para-text") & _
    vbCr & vbCr
    Next j
    End If
    Next k
    Set docReport = Documents.Add
    docReport.Range.InsertAfter strOutput
    End Sub
    '
    Function FindRefsToBookmark(bk As Bookmark) As Collection
    Dim f As Field
    Dim doc As Document
    Set doc = bk.Parent
    Dim colRefData As Collection
    Dim col As Collection
    Set colRefData = New Collection

    For Each f In doc.Fields
    Set col = New Collection
    If f.Type = wdFieldRef Then
    If Split(Trim(f.Code))(1) = bk.Name Then
    f.Select
    col.Add Key:="page", Item:=Selection.Information(wdActiveEndPageNumber)
    col.Add Key:="para-text", Item:=Selection.Paragraphs(1).Range.Text
    colRefData.Add Item:=col
    End If
    End If
    Set col = Nothing
    Next f
    If colRefData.count = 0 Then
    Set FindRefsToBookmark = Nothing
    Else
    Set FindRefsToBookmark = colRefData
    End If
    End Function
    </pre>


  3. #3
    Silver Lounger
    Join Date
    Jan 2001
    Location
    West Long Branch, New Jersey, USA
    Posts
    1,921
    Thanks
    6
    Thanked 9 Times in 7 Posts

    Re: Bookmark rpt (2003)

    Hi Andrew,

    Thanks much. I gave it a whirl and it works great (except that I had to select the document first before running your macro).

    I have a 60-pg document with lots of bookmarks. Some are there to allow me to navigate back to certain spots of the document. I would not expect any of these to be referenced from anywhere else in the doc. And so they weren't.

    However, there are many bookmarks that are used as part of a TOA entry in case the item spans more than a page. Of course, these bookmarks are part of the hidden text for the TA field. A quick check of 2 of my bookmarks in your "report" shows that neither of these had any Reference info in your report. But they are picked up in the TOA showing a span of pages (eg, "1-2"). The bookmarks that did show up in your "Referenced" info were just a few that were used in a different way (eg, to refer to specific text). The ones that did not show up were ones where I referenced a page # that the bookmarked text was on (eg, "see page x" where x is a cross-ref to a bookmark's page #).

    I also need to check the hidden bookmarks in terms of what they're referring to but that seems ok.

    Thanks.

    Fred

  4. #4
    3 Star Lounger
    Join Date
    Apr 2004
    Location
    Boston, Massachusetts, USA
    Posts
    389
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Bookmark rpt (2003)

    To pick up bookmarks within hidden text, you'd probably have to un-hide the text temporarily. As for refs to page numbers, are your page numbers in the footer? You may need to wrap another For..Each loop around the one that searches for fields to search every StoryRange so it'll pick up those page fields.

    Glad to hear the basic algorithm is sound -- hope you get it working to your specs.

  5. #5
    Silver Lounger
    Join Date
    Jan 2001
    Location
    West Long Branch, New Jersey, USA
    Posts
    1,921
    Thanks
    6
    Thanked 9 Times in 7 Posts

    Re: Bookmark rpt (2003)

    Hi Andrew,

    >To pick up bookmarks within hidden text, you'd probably have to un-hide the text temporarily.
    These are r switches within a TA field. Is what you're suggesting to do
    - a select all at the beginning and unhide any hidden text (only text that I have hidden is the {TA...} field. Can do.
    - go thru your macro as previously supplied
    - select all and re-hide TA fields. Not sure how to do this last - search for all { TA...} and hide. (I know the curly braces are not typed on the keyboard.)

    >As for refs to page numbers, are your page numbers in the footer? You may need to wrap another For..Each loop around the one that searches for fields to search every StoryRange so it'll pick up those page fields.
    Really not sure what you're suggesting here. I do have my page #s in a footer. What I was saying was that I have 2 types of bookmarks that refer to page#s:
    - I might say "as discussed above on page x" where x is inserted as a x-ref to a bookmark on page x where I discussed whatever
    - For a quotation from some reference that spans 2 pages, I have bookmarked the entire quotation. The bookmark is then included in the {TA field...}. That way, when a TOA is done, the entry for the authority is provided as "Authority title...x-y" where x-y are the start/end page numbers of the bookmark. Of course, the ref to the bookmark is in hidden text.

    Neither of the above uses of x-ref'g a bookmark to a page# shows the Referenced-by info for the bookmark.

    Fred

  6. #6
    4 Star Lounger
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    543
    Thanks
    56
    Thanked 0 Times in 0 Posts

    Re: Bookmark rpt (2003)

    Andrew

    I have been looking for something like this for ages. Thank you.

    I have multi page (up to 100) documents with bookmarks throughout and have created TOC so your macro gives me lots and lots of information. We also have some documents supplied by our software developer (CRM) that have bookmarks that we need to know what they are. I run Word with the Tools|Options|Views Bookmarks checked all the time but this does not show the names.

    Again thank you
    cheers

    Phil Carter

  7. #7
    Star Lounger
    Join Date
    Apr 2003
    Location
    Washington, District Of Columbia, USA
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Bookmark rpt (2003)

    This work well. Could you help me to sort those bookmarks so they come out in location order. Thanks.

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Bookmark rpt (2003)

    Here is a different and shortened version of Andrew's macro. It produces a table in a new document listing bookmarks in the order they appear in the document. You can adapt it to your needs.

    Sub GetBookmarkInfo()
    Dim bk As Bookmark
    Dim colBkData As Collection
    Dim col As Collection
    Dim colRefs As Collection
    Dim doc As Document
    Dim strOutput As String
    Dim k As Long
    Dim docReport As Document

    Set colBkData = New Collection
    Set doc = ActiveDocument
    doc.Bookmarks.ShowHidden = True

    For Each bk In doc.Bookmarks
    Set col = New Collection
    col.Add Key:="name", Item:=bk.Name
    col.Add Key:="start", Item:=bk.Start
    colBkData.Add Item:=col
    Set col = Nothing
    Next bk
    Set docReport = Documents.Add
    docReport.Tables.Add _
    Range:=Selection.Range, _
    NumRows:=1, NumColumns:=2
    Selection.TypeText Text:="Bookmark name"
    Selection.MoveRight Unit:=wdCell
    Selection.TypeText Text:="Starting position"
    For k = 1 To colBkData.Count
    Selection.MoveRight Unit:=wdCell
    Selection.TypeText Text:=colBkData(k)("name")
    Selection.MoveRight Unit:=wdCell
    Selection.TypeText Text:=colBkData(k)("start")
    Next k

    docReport.Tables(1).Sort ExcludeHeader:=True, _
    FieldNumber:=2, SortFieldType:=wdSortFieldNumeric
    End Sub

  9. #9
    Star Lounger
    Join Date
    Apr 2003
    Location
    Washington, District Of Columbia, USA
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Bookmark rpt (2003)

    Thanks Hans, do you think it would be possible to look through several unopened documents and pull the bookmarks out into a new document?

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Bookmark rpt (2003)

    Would you like to collect information on all Word documents in a folder, or would you like the user to be able to select specific documents?

  11. #11
    Star Lounger
    Join Date
    Apr 2003
    Location
    Washington, District Of Columbia, USA
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Bookmark rpt (2003)

    Within a specfied folder.

  12. #12
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Bookmark rpt (2003)

    Try the attached code.
    Attached Files Attached Files

  13. #13
    Star Lounger
    Join Date
    Apr 2003
    Location
    Washington, District Of Columbia, USA
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Bookmark rpt (2003)

    Works good. I'm trying to get the bookmark text out of each bookmark in the documents. I've been trying to merge you previous attachment with something i've been working on that was giving me the output of the active document only. I've managed to get that with the attached but it seems to pulling the bookmarks multiple times from each document in the selected folder. Could you please see if you can figure where my problem is. Except for this is perfect.
    Attached Files Attached Files

  14. #14
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Bookmark rpt (2003)

    You don't reset strOutput to an empty string for each document, so you keep on appending text to the string. Insert a line

    strOutput = ""

    immediately below the line

    Do While Not strFile = ""

  15. #15
    Star Lounger
    Join Date
    Apr 2003
    Location
    Washington, District Of Columbia, USA
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Bookmark rpt (2003)

    Thanks Much Hans, work great.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •