Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Denmark
    Posts
    347
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Bookmarks in shapes (WinXP/O2003)

    Hi,

    I've got a template where I'm inserting various items extracted from a database.
    These items are inserted at locations marked by hidden bookmarks.
    On the last page of the document I have a table within a textbox - in the table there's 5 bookmarks.

    My problem is that I can't "see" the bookmarks in the textbox, when using the ".goto bookmark" and instead gets an error.
    (5678 - Can't find requested bookmark)

    My code looks something like this...(fraction of it only...)

    STEP1
    With ActiveDocument.Bookmarks
    .DefaultSorting = wdSortByName
    .ShowHidden = True
    If .Exists(strBookmarkUPDIs) = False Then
    If .Exists(strBookmarkIs) = True Then
    With Selection
    .GoTo what:=wdGoToBookmark, Name:=strBookmarkIs
    If .Information(wdWithInTable) Then
    .SelectCell
    .Delete
    .Collapse Direction:=wdCollapseStart
    End If
    .....

    Then I tried to see if I could catch it through the shapes collection with this bit added as errorhandler.

    STEP2
    Bookmark_FindCustom = False

    With ActiveDocument
    i = .Shapes.Count
    For Each s In .Shapes
    s.Select
    blnShowStatus = .Bookmarks.ShowHidden
    .Bookmarks.DefaultSorting = wdSortByName
    .Bookmarks.ShowHidden = True

    If .Bookmarks.Exists(strBookmarkIs) = True Then
    Selection.GoTo what:=wdGoToBookmark, Name:=strBookmarkIs
    Bookmark_FindCustom = True
    Exit Function
    End If
    Next s
    .Bookmarks.ShowHidden = blnShowStatus
    End With

    .... then I'll return to STEP1 at the line just after the .Goto Bookmark with a Resume next...

    Any good suggestions on how to solve this "hidden" issue?
    Bests,
    RD


    PS: Wish there were a knob on the TV to turn up the intelligence. There's a knob called "brightness," but that doesn't work

  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Bookmarks in shapes (WinXP/O2003)

    Try iterating through each StoryRange in ActiveDocument.StoryRanges - this should get all shapes, headers, footers, etc.
    You may need a check on StoryRange.Type such as (completely untested code...)

    Dim rngStory as Range
    For Each rngStory in ActiveDocument.StoryRanges
    With rngStory
    Select Case .StoryType
    Case wdCommentsStory, wdEndnotesStory
    <font color=448800>' We don't want to do anything to comments or end notes </font color=448800>
    Case Else
    <font color=448800>' Do your processing here </font color=448800>

    End Select
    End With
    Next StoryRange

    StuartR

  3. #3
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Bookmarks in shapes (WinXP/O2003)

    Henrik,

    It's not clear from your code, exactly what you're doing with the bookmark, once you locate it, but it is clear that you're locating the bookmark via Selection, which isn't the usual way to locate a bookmark via code.

    If you use syntax like:

    <pre>ActiveDocument.Bookmarks("strBookmarkIs")</pre>

    you can do whatever you want to the bookmark as a range, without having to actually visit it via Selection - for example:
    <pre>ActiveDocument.Bookmarks("strBookmarkIs").Ran ge.Text = strText</pre>

    The benefit of this method is that it allows you to locate and manipulate any bookmark in any story range in the document.

    Gary

Posting Permissions

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