Results 1 to 8 of 8
  1. #1
    2 Star Lounger
    Join Date
    Jan 2001
    Posts
    114
    Thanks
    0
    Thanked 0 Times in 0 Posts

    add BookMk in header (Word 2003 )

    I am attempting to add a bookmark to the header using the range object.
    I want to set the Bkmk in the
    1st section, 1st page header, 2nd Table, 2nd column, 1st cell, last paragraph
    I get the Bkmk containing the entire cell or the first word but I cannot discover the correct syntx to get it locate in the last paragraph or any particular paragraph.
    Please help
    Thank you

  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
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: add BookMk in header (Word 2003 )

    Can you show us the syntax you use to select the first word, and we may be able to advise you how to modify it to select the last paragraph in the cell.

    One thing to watch is that selecting the last paragraph in a table cell can be tricky because the paragraph marker is actual the cell marker, and you need to reduce the end of your range by a character to step back over this.

    StuartR

  4. #3
    2 Star Lounger
    Join Date
    Jan 2001
    Posts
    114
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: add BookMk in header (Word 2003 )

    I tried to reply earlier but there was no response from wopr.com.
    This is the code I am using
    Dim HderTables As Range
    Set HderTables = ActiveDocument.Sections(1).Headers(wdHeaderFooterF irstPage).Range
    -- other lines of functioning code --
    HderTables.Bookmarks.Add BkHamilton, HderTables.Tables(2).Columns(2).Cells(1).Range.Wor ds(x)
    I have 7 paragraphs with text and the 8th is empty except for a space character. I want to set a bookmark at the space so that another routine can use it if necessary.
    The .range.words(x) is the only syntax tht I have found allowing me to move around in the cell.
    The number of paragraphs can change so I am looking for an object property that will get me to the last paragraph in the cell.
    Any help is greatly appreciated.

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

    Re: add BookMk in header (Word 2003 )

    This code seems to work OK, I'm sure it could be more elegant and you may want to add some error handling to make sure that there are the right numbers of Tables with the appropriate columns

    StuartR

    <code>
    Dim HderTables As Range
    Const BkHamilton As String = "Hamilton"
    Set HderTables = ActiveDocument.Sections(1).Headers(wdHeaderFooterF irstPage).Range.Tables(2).Columns(2).Cells(1).Rang e
    <font color=448800>' Step back over end of cell marker </font color=448800>
    HderTables.MoveEnd Unit:=wdCharacter, Count:=-1
    HderTables.Collapse Direction:=wdCollapseEnd
    HderTables.Bookmarks.Add Name:=BkHamilton, Range:=HderTables
    </code>

  6. #5
    2 Star Lounger
    Join Date
    Jan 2001
    Posts
    114
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: add BookMk in header (Word 2003 )

    Stuart:
    I have just tried your code. I get the bookmark added but it appears to include all contents of the cell. I want only the space in the last paragraph to be included in the bookmark.
    Since I have HderTables defined earlier as
    Set HderTables = ActiveDocument.Sections(1).Headers(wdHeaderFooterF irstPage).Range
    I used this coding to add the bookmark:
    HderTables.Tables(2).Columns(2).Cells(1).Range.Mov eEnd Unit:=wdCharacter, Count:=-1
    HderTables.Tables(2).Columns(2).Cells(1).Range.Col lapse Direction:=wdCollapseEnd
    HderTables.Tables(2).Columns(2).Cells(1).Range.Boo kmarks.Add Name:=BkHamilton, Range:=HderTables.Tables(2).Columns(2).Cells(1).Ra nge

    Norman

    Norman

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

    Re: add BookMk in header (Word 2003 )

    That doesn't look right. You need to either define a new range object, or set a new value for HderTables.

    Either
    <code>Dim rngHamilton as Range
    Set rngHamilton = HderTables.Range.Tables(2).Columns(2).Cells(1).Ran ge
    rngHamilton.MoveEnd Unit:=wdCharacter, Count:=-1
    rngHamilton.Collapse Direction:=wdCollapseEnd
    rngHamilton.Bookmarks.Add Name:=BkHamilton, Range:=rngHamilton</code>

    or
    <code>set HderTables = HderTables.Range.Tables(2).Columns(2).Cells(1).Ran ge
    HderTables.MoveEnd Unit:=wdCharacter, Count:=-1
    HderTables.Collapse Direction:=wdCollapseEnd
    HderTables.Bookmarks.Add Name:=BkHamilton, Range:=HderTables</code>

    When you add the bookmark you must have a RANGE object that has been defined so that it excludes the cell marker.

    StuartR

  8. #7
    2 Star Lounger
    Join Date
    Jan 2001
    Posts
    114
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: add BookMk in header (Word 2003 )

    Thank you Stuart. Everything works fine now. I used your your first coding suggestion.
    It looks very similar to mine. Please explain what the subtle difference is.
    I do not understand your comment about needing to "define a new range object".
    Norman

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

    Re: add BookMk in header (Word 2003 )

    Your code included the line
    <code>HderTables.Tables(2).Columns(2).Cells(1).Ran ge.Bookmarks.Add Name:=BkHamilton, Range:=HderTables.Tables(2).Columns(2).Cells(1).Range
    </code>
    Which set the bookmark to cover the range shown in bold. This range includes the whole contents of the cell.

    In my code I used a range object (HderRange or rngHamilton) that I first set to the value you used, and then Moved back by one character (to skip the end of cell marker) and collapsed (so that it was just an insertion point).

    StuartR

Posting Permissions

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