Export (0) Print
Expand All
Expand Minimize

How to: Hide Text in Documents

NoteNote

Some code examples in this topic use the this or Me keyword or the Globals class in a way that is specific to document-level customizations, or they rely on features of document-level customizations such as host controls. These examples can be compiled only if you have the required applications installed. For more information, see Features Available by Product Combination.

You can hide text in a document by setting the Hidden property of the Font for a particular range of text. For example, you can temporarily hide the text within a Bookmark control before printing your document.

To hide text in a Bookmark control while printing the document

  1. Create a procedure that hides the text of the given range.

    static void HideText(Microsoft.Office.Interop.Word.Range rng)
    {
        rng.Font.Hidden = 1;  // 1 = True
    }
    
    
  2. Create a procedure that unhides the text of a given range.

    static void UnhideText(Microsoft.Office.Interop.Word.Range rng)
    {
        rng.Font.Hidden = 0;  // 0 = False
    }
    
    
  3. Pass the range of a Bookmark control to the HideText method, print the document, and then pass the same range to the UnhideText method.

    HideText(bookmark1.Range);
    
    object oTrue = true;
    object oFalse = false;
    object range = Word.WdPrintOutRange.wdPrintAllDocument;
    object items = Word.WdPrintOutItem.wdPrintDocumentContent;
    object copies = "1";
    object pages = "";
    object pageType = Word.WdPrintOutPages.wdPrintAllPages;
    
    this.PrintOut(
        ref oTrue, ref oFalse, ref range, ref missing, ref missing, ref missing,
        ref items, ref copies, ref pages, ref pageType, ref oFalse, ref oTrue,
        ref missing, ref oFalse, ref missing, ref missing, ref missing, ref missing);
    
    UnhideText(bookmark1.Range);
    
    

Compiling the Code

This code example assumes you have an existing Bookmark control named Bookmark1 on the document.

See Also

Community Additions

ADD
Show:
© 2014 Microsoft