locked
Turning one Word Bookmark into two separated Bookmarks RRS feed

  • Question

  • Hi!

     

    I'm building a Word 2003 addin with VSTO 2005 SE. In my solution I need a method which should turn an existing Bookmark into two Bookmarks with a blank space in between. The original Bookmark is located in a Table cell in the document header. Before the method runs it looks something like this (brackets represent start and end of a bookmark):

     

    [Content]

     

    When the method is done I want it to look something like this:

     

    [NewContent] [Content]

     

    None of the different methods I've tried work. Does anyone have any good ideas?

     

    Help is always greatly appreciated...

     

    //Herman

     

    Wednesday, August 1, 2007 7:52 AM

Answers

  • Hi Hermann

     

    When I need something like this, I work with range objects. Declare two range objects. Assign one of them to the bookmark range. Assign the other to that Range's Duplicate. Roughly (off the top of my head, untested)

    Dim rngB1 as Word.Range

    Dim rngB2 as Word.Range

     

    rngB1 = doc.Bookmarks("Content").Range

    rngB2 = rngB1.Duplicate

     

    Then I'd probably continue like this

    rngB2.InsertBefore " "

    rngB2.Collapse Word.WdCollapseDirection.wdCollapseStart

    'Should put the range in front of the space

    rngB2.Text = "The new content"

    doc.Bookmarks.Add(rngB2, "NewContent")

     

    Wednesday, August 1, 2007 2:58 PM

All replies

  • Hi Hermann

     

    When I need something like this, I work with range objects. Declare two range objects. Assign one of them to the bookmark range. Assign the other to that Range's Duplicate. Roughly (off the top of my head, untested)

    Dim rngB1 as Word.Range

    Dim rngB2 as Word.Range

     

    rngB1 = doc.Bookmarks("Content").Range

    rngB2 = rngB1.Duplicate

     

    Then I'd probably continue like this

    rngB2.InsertBefore " "

    rngB2.Collapse Word.WdCollapseDirection.wdCollapseStart

    'Should put the range in front of the space

    rngB2.Text = "The new content"

    doc.Bookmarks.Add(rngB2, "NewContent")

     

    Wednesday, August 1, 2007 2:58 PM
  • Hi Cindy!

     

    From the look of your suggestion it looks like it would solve my problem.

     

    Thanks a lot for the help...

     

    //Herman

     

    Wednesday, August 1, 2007 3:03 PM