programmatically inserting hidden text into a Word 2010 table RRS feed

  • Question

  • I have a Word 2010 table with existing, visible text in each cell. I want to use some VBA code to insert some text into each cell and then hide the new text. I know how to insert text into a cell using VBA, I just can't figure out how to leave the existing text in the cell visible and only hide the new text.
    Thursday, December 19, 2013 9:46 PM

All replies

  • You need to use a range and format the range e.g.

    Dim oCell As Range
        'identify the cell and set that cell as a range
        Set oCell = ActiveDocument.Tables(1).Cell(1, 1).Range
        'Move the end of the range inside the cell end marker
        oCell.End = oCell.End - 1
        'Collapse the range - here to the end of the cell range
        oCell.Collapse wdCollapseEnd
        'Type the hidden text
        oCell.Text = "This is the hidden text"
        'Format it as hidden
        oCell.Font.Hidden = True

    Depending on the use of this hidden text I would suggest treating with caution as hidden text is all too easily re-displayed by the user,

    Graham Mayor - Word MVP

    Friday, December 20, 2013 7:56 AM