Results 1 to 4 of 4
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Bookmarks straddle rows (Word97)

    Here's something that is puzzling me: I recorded the macro below as a sure-fire way (Word97) of duplicating a problem at will.

    I have code that builds tables in Word documents, and the inserted text is bookmarked. I noticed that the bookmarks weren't behaving as they should.

    In particular, I was loading text into column2 of each row, but using column1 to store a bookmark label in text form, and then bookmarking THAT text. The bookmarks would allow my program code to navigate the tables, the text forms would allow us humans to see what was going on "under the hood".

    I created a bookmark on the text in a cell of column1, and could see that the bookmark "square brackets" were wholly contained within the cell, but adding a row to the end of the table under program control seems to stretch that bookmark to straddle two rows of the table!


    <pre>Sub Macro1()
    '
    ' Macro1 Macro
    ' Macro recorded 12/15/03 by Christopher Greaves
    '
    Documents.Add

    ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=2, NumColumns:=3
    Selection.TypeText Text:="A"
    Selection.MoveRight Unit:=wdCell
    Selection.TypeText Text:="B"
    Selection.MoveRight Unit:=wdCell
    Selection.TypeText Text:="D"
    Selection.MoveRight Unit:=wdCell
    Selection.TypeText Text:="D"
    Selection.MoveRight Unit:=wdCell
    Selection.TypeText Text:="E"
    Selection.MoveRight Unit:=wdCell
    Selection.TypeText Text:="F"

    Dim rng As Range
    Set rng = Selection.Tables(1).Range

    ActiveDocument.Bookmarks.Add Name:="Bkmk1", Range:=rng.Tables(1).Rows(rng.Tables(1).Rows.Count ).Cells(1).Range
    MsgBox "Note the bookmark in column1, row 2"

    rng.Tables(1).Rows.Add
    Dim rngAddToTable As Range
    Set rngAddToTable = rng.Tables(1).Rows(rng.Tables(1).Rows.Count).Cells (1).Range
    ActiveDocument.Bookmarks.Add Name:="Bkmk2", Range:=rng.Tables(1).Rows(rng.Tables(1).Rows.Count ).Cells(1).Range

    MsgBox "Note that the bookmark now straddles rows 1 & 2 in column1"
    End Sub
    </pre>


  2. Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Bookmarks straddle rows (Word97)

    Hi Chris,

    Looks like it's "by design", and the design does seem to make some sense.
    With the implementation as it is, you can bookmark a column, and the whole column will stay bookmarked even after you add more rows.

    If you don't include the end-of-cell marker in the bookmark, the bookmark won't change if you add another row.

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> Klaus

  4. #3
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Bookmarks straddle rows (Word97)

    This is a guess, but I ran into a problem getting VBA to walk down a Word table row by row and discovered the apparent randomness that was sneaking into the program result had to do with -- strangely enough -- the fact that Word was set Print Preview. Testing for that and setting view to Normal fixed the problem. Here's a code fragment you can put at the beginning of the VBA to set teh view to Normal. If it works, great, if not... <img src=/S/broke.gif border=0 alt=broke width=31 height=23>

    If ActiveWindow.View.SplitSpecial = wdPaneNone Then
    ActiveWindow.ActivePane.View.Type = wdNormalView
    Else
    ActiveWindow.View.Type = wdNormalView
    End If

  5. #4
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Bookmarks straddle rows (Word97)

    Klaus, thanks for this. It got buried back in history in my In Box.

    I see what you are saying. I set the bookmark without the end-of-cell marker, and it behaves as i wanted. I need to be more careful in deciding just what to bookmark.

    Having the bookmark extended when adding a row surely is helpful for the case you stated. I'd not considered that I could choose between the "cell structure" (which includes the end-of-cell marker) and the "cell contents".

Posting Permissions

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