Results 1 to 6 of 6
  1. #1
    Star Lounger
    Join Date
    Mar 2001
    Location
    Cheltenham, Pennsylvania, USA
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VBA/Bookmarks (Word 2000)

    This is a VBA issue in a document automation project. I'm more comfortable here than in the VBA forum, so I hope I can get some help from people I'm already familiar with.

    I'm hitting a wall when trying to pass a string variable to a reference to a bookmark. I know that the argument is supposed to be an index value, but if I pass the raw string itself, it works fine. To explain:

    ActiveDocument.Bookmarks("name of a bookmark").whatever works fine.

    If I define a string variable (strMyBookmark) as set it equal to "name of a bookmark" I'd expect it to work, but I find that ActiveDocument.Bookmarks(strMyBookmark).whatever fails.

    The workaround (identifying the index of each bookmark) will be slightly ugly, and I'm hoping to avoid it.

    Any ideas? I'm brand new at this stuff, and your help is appreciated. Thanks.

  2. #2
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA/Bookmarks (Word 2000)

    Larry,

    This worked for me:<pre>Dim strBookmark As String
    strBookmark = "thisBookmark"
    ActiveDocument.Bookmarks(strBookmark).Select
    </pre>

    I assume you didn't have spaces in your real bookmark name?
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

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

    Re: VBA/Bookmarks (Word 2000)

    ...or any of a whole slew of other characters that are forbidden in bookmark names? eg.:

    <pre>! @ # $ % ^ & * ( ) - = + { } [ ] | ; : ' " , . < > / ? ~ ` </pre>

    Gary

  4. #4
    Star Lounger
    Join Date
    Mar 2001
    Location
    Cheltenham, Pennsylvania, USA
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA/Bookmarks (Word 2000)

    Gary & Geoff:

    The bookmark "index" string does include an underscore, but it does not use any of the forbidden characters or spaces. It kicked out an error code that I'll recreate and pass along to you on Monday from work. I noticed while debugging that VBA reported the current value of the dynamically-built variable correctly (as a quoted string), yet it still hiccoughed.

  5. #5
    Star Lounger
    Join Date
    Mar 2001
    Location
    Cheltenham, Pennsylvania, USA
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA/Bookmarks (Word 2000)

    Additional information: the error code I'm gettting is 5491 "The requested member of the collection does not exist." However, the string being passed as the bookmark name is correct, and a bookmark with that exact name does exist. Thanks for any other suggestions.

  6. #6
    Star Lounger
    Join Date
    Mar 2001
    Location
    Cheltenham, Pennsylvania, USA
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA/Bookmarks (Word 2000)

    I found the answer, so here it is in case anyone else is interested.

    I was building the string that holds the name of the bookmark by concatenating a string, a varying integer, and another string..... strA & str(i) & strB

    The Str() function was inserting a space before the digit (as the sign placeholder) for the "i".

    The correction is to use the CStr function instead, which does not insert the leading space....
    strA & CStr(i) & strB

    (When I checked the value that was being evaluated for the string I failed to notice the space.)

Posting Permissions

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