Welcome to Telelogic Product Support
  Home Downloads Knowledgebase Case Tracking Licensing Help Telelogic Passport
Telelogic DOORS (steve huntington)
Decrease font size
Increase font size
Topic Title: Add Bookmark to word document
Topic Summary: Word Bookmarks
Created On: 26-Jan-2007 06:00
Status: Post and Reply
Linear : Threading : Single : Branch
Search Topic Search Topic
Topic Tools Topic Tools
Quick Reply Quick Reply
Subscribe to this topic Subscribe to this topic
E-mail this topic to someone. E-mail this topic
Bookmark this topic Bookmark this topic
View similar topics View similar topics
View topic in raw text format. Print this topic.
 26-Jan-2007 06:00
User is offline View Users Profile Print this message


Andrew Tagg

Posts: 151
Joined: 26-Oct-2004

I spent a while surfing the forum for advice on Word Bookmarks. Found advice on how to select an existing bookmark, but nothing on how to add one in the first place.  Here is my contribution:
    /////////////////////////////////////////////////////////////////////////////////////////////
    //insert bookmark VBA Equivalent
    /////////////////////////////////////////////////////////////////////////////////////////////
    //  With ActiveDocument.Bookmarks
    //     .Add Range:=Selection.Range, Name:="myBookmark"
    //   End With
    ////////////////////////////////////////////////////////////////////////////////////////////
   
    //Retrieve the bookmarks collection
    OleAutoObj objBookMarks
    oleGet(objDoc, "Bookmarks", objBookmarks)
   
    clear objArgBlock
    put(objArgBlock, "Name", "myBookmark")
    oleMethod(objBookmarks, cMethodAdd, objArgBlock)


have fun.
Rgds
Andrew

-------------------------
Andrew Tagg
Thales Air Systems, Melbourne
Australia.
andrew.tagg@thalesatm.com
Report this to a Moderator Report this to a Moderator
 29-Jan-2007 08:21
User is offline View Users Profile Print this message


Andrew Tagg

Posts: 151
Joined: 26-Oct-2004

Additional to the post above, the following expands the idea to put a 'start' bookmark, some content, then an 'end' bookmark, then select the in between content and do something useful with it in Word.

This example is for making a table out of a delimited text string, which gives a huge speed increase to table export to Word, but unfortunately is of limited use due to a 'feature' of the Word stringToTable routine.  Basically if Word sees a carriage return it will jump to the next cell, rather than making two rows of text within one cell.   Ahhh back to the drawing board as they say.

I do have a routine to remove any naughty carriage returns, but the output is not as satisfactory as it could be.




 //Make table from delimited string 
    const string cMethodConvertToTable           = "ConvertToTable" //should be there already in ole.inc
    const string wdTableFieldSeparator           = "Separator"
    const string wdNumRows                       = "NumRows"
    const string wdNumColumns                    = "NumColumns"
    int          wdSeparateByCommas              = 2
    int          wdSeparateByTabs                = 1
       
 

    //insert bookmark VBA Equivalent
    ////////////////////////////////////////////////////////
    //  With ActiveDocument.Bookmarks
    //     .Add Range:=Selection.Range, Name:="tableStart"
    //   End With
    ////////////////////////////////////////////////////////
       
    //Make some declarations
    OleAutoObj objBookMarks
    OleAutoObj oleStartBookmark
    OleAutoObj oleEndBookmark
    int START_POSITION
    int END_POSITION
   
   
    //Retrieve the bookmarks collection
    oleGet(objDoc, "Bookmarks", objBookmarks)
   
    //Add a bookmark before the table
    clear objArgBlock
    put(objArgBlock, "Name", "Start")
    oleMethod(objBookmarks, cMethodAdd, objArgBlock)
   
    //Paste the delimited string
   string otext = tempStringOf(b_parsedDelimitedTable)
   setRichClip(richText otext, "Body Text")
   oleMethod(objSel, cMethodPaste) 
 
   //Add a bookmark after the table
   clear objArgBlock
   put(objArgBlock, "Name", "End")
   oleMethod(objBookmarks, cMethodAdd, objArgBlock)
 
   //go back to the Start bookmark and collapse selection
   clear objArgBlock
   put(objArgBlock, "Start") 
   oleMethod(objBookmarks, "Item", objArgBlock, oleStartBookmark) 
   oleMethod(oleStartBookmark, "Select")
   collapseSelection
    
   //set the range start
   oleGet(objSel,"Range",objRange)
   oleGet(objRange,"Start",START_POSITION)
    
   //go back to the End bookmark and collapse selection
   clear objArgBlock
   put(objArgBlock, "End") 
   oleMethod(objBookmarks, "Item", objArgBlock, oleEndBookmark) 
   oleMethod(oleEndBookmark, "Select")
   collapseSelection    
    
   //set the range end
   oleGet(objSel,"Range",objRange)
   oleGet(objRange,"End",END_POSITION)

   //select the range
   oleGet(objSel,"Range",objRange)
   olePut(objRange,"Start",START_POSITION)
   olePut(objRange,"End",END_POSITION)
   oleMethod(objRange, "Select")
    
   //convert to table       
   clear objArgBlock
   put(objArgBlock,  wdTableFieldSeparator,  wdSeparateByTabs)
   put(objArgBlock,  wdNumRows,              noRows)
   put(objArgBlock,  wdNumColumns,           noCols)
   oleMethod(objSel, cMethodConvertToTable,  objArgBlock)
     
   collapseSelection

/////////////////////////////////

enjoy.



-------------------------
Andrew Tagg
Thales Air Systems, Melbourne
Australia.
andrew.tagg@thalesatm.com
Report this to a Moderator Report this to a Moderator
Statistics
20925 users are registered to the Telelogic DOORS forum.
There are currently 2 users logged in.
The most users ever online was 15 on 15-Jan-2009 at 16:36.
There are currently 0 guests browsing this forum, which makes a total of 2 users using this forum.
You have posted 0 messages to this forum. 0 overall.

FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.