none
How to use the function. InsertSymbol in a VSTO project RRS feed

  • Question

  • I'm having problems when I'm trying to insert into a second cell of a table of my template 's Wingdings 2 character, the problem is that following some forums when I get up to insert it, it appears in the first table, I believe it has something to do with a selected property I do not understand right:

    eg

    this.Tables [ 2 ]. Cell (1, 1). Range.InsertSymbol (152, " Wingdings 2 ", true, Word.WdFontBias.wdFontBiasDefault );

     

    appears an exception

    This method or property is not available because the object does not refer to a range or selection simple.

     

    but if I try to set as it is explained in some forums:

    Word.Selection this.Tables selection = [ 2 ]. Cell (1,1). Application.Selection;

     

                 selection.SetRange (1, 1);

     

                 selection.InsertSymbol (152, " Wingdings 2 ", true, Word.WdFontBias.wdFontBiasDefault );

     

    But the symbol is inserted in cell ( 1,2) table, I think this has to do with knowing I'm not grinding set right, help please ^ ^ .
    Sunday, August 14, 2011 4:32 AM

Answers

  • Hi Drinith

    A cell Range contains the cell structures in addition to the cell text. If you work with a table in the UI this is the difference between clicking at the left edge of a cell  (the entire cell is selected) and pressing TAB to enter a cell (only the text is selected). If the entire cell is selected and you press the left-arrow key you get a blinking cursor or, if the cell contains text, holding the Shift key and press the left-arrow only the text is selected, not the entire cell.

    In order to get this state using the Range object you have a number of possibilities. The one I usually use is

    Word.Range rngTable = this.Tables [ 2 ]. Cell (1, 1).Range;
    object oCollapseStart = Word.WdCollapseDirection.wdCollapseStart;
    rngTable.Collapse(ref oCollapseStart);
    rngTable.InsertSymbol (152, " Wingdings 2 ", true, Word.WdFontBias.wdFontBiasDefault );

    which is the equivalent of pressing the left-arrow when the entire cell is selected.


    Cindy Meister, VSTO/Word MVP
    Sunday, August 14, 2011 7:17 AM
    Moderator
  • Thank you Cindy Meister
    • Marked as answer by Drinith Sunday, August 21, 2011 4:48 PM
    Sunday, August 21, 2011 4:48 PM

All replies

  • Hi Drinith

    A cell Range contains the cell structures in addition to the cell text. If you work with a table in the UI this is the difference between clicking at the left edge of a cell  (the entire cell is selected) and pressing TAB to enter a cell (only the text is selected). If the entire cell is selected and you press the left-arrow key you get a blinking cursor or, if the cell contains text, holding the Shift key and press the left-arrow only the text is selected, not the entire cell.

    In order to get this state using the Range object you have a number of possibilities. The one I usually use is

    Word.Range rngTable = this.Tables [ 2 ]. Cell (1, 1).Range;
    object oCollapseStart = Word.WdCollapseDirection.wdCollapseStart;
    rngTable.Collapse(ref oCollapseStart);
    rngTable.InsertSymbol (152, " Wingdings 2 ", true, Word.WdFontBias.wdFontBiasDefault );

    which is the equivalent of pressing the left-arrow when the entire cell is selected.


    Cindy Meister, VSTO/Word MVP
    Sunday, August 14, 2011 7:17 AM
    Moderator
  • Thank you Cindy Meister
    • Marked as answer by Drinith Sunday, August 21, 2011 4:48 PM
    Sunday, August 21, 2011 4:48 PM