none
How to make a selected text invisible on the page? RRS feed

  • Question

  • Hi,

    I want to be able by code to "erase" the portion of text selected, in a way that after my macro is applied, instead of the selected words there will be a blank in the same color of the background, something like that:

    before:

    TEXT TEXT TEXT

    after:

    TEXT          TEXT

    or even better:

    TEXT _ _ _TEXT

    I can achieve that very easly:

     

    Public Sub Magic()
    With Selection.Font
    .Underline = wdUnderlineDash
    .UnderlineColor = wdColorBlack
    .Color = wdColorWhite
    End With
    End Sub

    But if the color of the page or the paragraph is not white and/or the font color is not black?

    The following works only if the page is white:

    Public Sub NotSoMagic()
    With Selection.Font
    .Underline = wdUnderlineDash
    .UnderlineColor = wdColorBlack
    .Color = ActiveDocument.Background.Fill.BackColor
    End With
    End Sub
    And the following doesn't work at all:
    Public Sub NotMagicAtAll()
    With Selection.Font
    .Underline = wdUnderlineDash
    .UnderlineColor = .Color
    .Color = Selection.Shading.BackgroundPatternColor
    End With
    End Sub

     

    Do you please have ant suggestions?

    Thanks, Lauro

     

    Tuesday, January 18, 2011 10:20 PM

Answers

  • Another alternative would be to control the position of the text after that which you want to hide by means of a tab stop and then format the font of the word (only, not the tab space after the work) that you want to hide as hidden

    With the display of hidden text turned off, the word that has the hidden font will not appear, and the following text will remain in place.


    Hope this helps.

    Doug Robbins - Word MVP,
    dkr[atsymbol]mvps[dot]org
    Posted via the Community Bridge

    "Lauro2" wrote in message news:d8140c9e-8b18-4e61-a1cb-94c6ba7f794e@communitybridge.codeplex.com...

    Hi,

    I want to be able by code to "erase" the portion of text selected, in a way that after my macro is applied, instead of the selected words there will be a blank in the same color of the background, something like that:

    before:

    TEXT TEXT TEXT

    after:

    TEXT          TEXT

    or even better:

    TEXT _ _ _TEXT
    I can achieve that very easly:

    Public Sub Magic()
    
     With Selection.Font
    
      .Underline = wdUnderlineDash
    
      .UnderlineColor = wdColorBlack
    
      .Color = wdColorWhite
    
     End With
    
    End Sub
    
    
    But if the color of the page or the paragraph is not white and/or the font color is not black?
    The following works only if the page is white:
    Public Sub NotSoMagic()
    
    With Selection.Font
    
     .Underline = wdUnderlineDash
    
     .UnderlineColor = wdColorBlack
    
     .Color = ActiveDocument.Background.Fill.BackColor
    
    End With
    
    End Sub
    
    

    And the following doesn't work at all:

    [code]
    Public Sub NotMagicAtAll()

    With Selection.Font

      .Underline = wdUnderlineDash

      .UnderlineColor = .Color

      .Color = Selection.Shading.BackgroundPatternColor

    End With

    End Sub



    [/code]



    Do you please have ant suggestions?

    Thanks, Lauro


    Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org
    Tuesday, January 18, 2011 10:59 PM
  • If your 'hidden' text is only supposed to be viewable via the macro and not printable, why is it in the body of the document at all? Why not simply display a message box with the 'hidden' information?

    Alternatively, you could have custom document property to toggle the display state of the contents of an IF field, coded along the lines of:
    {IF{DOCPROPERTY ShowText}= 1 "Text to Display" "______"}
    where 'ShowText' is the name of your custom document property and you macro sets this to 1 or 0, following which you execute the command:
    ActiveDocument.Fields.Update


    Cheers
    Paul Edstein
    [MS MVP - Word]
    Thursday, January 20, 2011 1:18 AM

All replies

  • Another alternative would be to control the position of the text after that which you want to hide by means of a tab stop and then format the font of the word (only, not the tab space after the work) that you want to hide as hidden

    With the display of hidden text turned off, the word that has the hidden font will not appear, and the following text will remain in place.


    Hope this helps.

    Doug Robbins - Word MVP,
    dkr[atsymbol]mvps[dot]org
    Posted via the Community Bridge

    "Lauro2" wrote in message news:d8140c9e-8b18-4e61-a1cb-94c6ba7f794e@communitybridge.codeplex.com...

    Hi,

    I want to be able by code to "erase" the portion of text selected, in a way that after my macro is applied, instead of the selected words there will be a blank in the same color of the background, something like that:

    before:

    TEXT TEXT TEXT

    after:

    TEXT          TEXT

    or even better:

    TEXT _ _ _TEXT
    I can achieve that very easly:

    Public Sub Magic()
    
     With Selection.Font
    
      .Underline = wdUnderlineDash
    
      .UnderlineColor = wdColorBlack
    
      .Color = wdColorWhite
    
     End With
    
    End Sub
    
    
    But if the color of the page or the paragraph is not white and/or the font color is not black?
    The following works only if the page is white:
    Public Sub NotSoMagic()
    
    With Selection.Font
    
     .Underline = wdUnderlineDash
    
     .UnderlineColor = wdColorBlack
    
     .Color = ActiveDocument.Background.Fill.BackColor
    
    End With
    
    End Sub
    
    

    And the following doesn't work at all:

    [code]
    Public Sub NotMagicAtAll()

    With Selection.Font

      .Underline = wdUnderlineDash

      .UnderlineColor = .Color

      .Color = Selection.Shading.BackgroundPatternColor

    End With

    End Sub



    [/code]



    Do you please have ant suggestions?

    Thanks, Lauro


    Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org
    Tuesday, January 18, 2011 10:59 PM
  • Thanks Doug for your suggestion.

    I still prefer to leave the user to freely performs the Show/Hide Hidden click as usually, without my disturbing hidden text. I others words, I want to give the user the possibility to click on a button and see my hidden text only if he want and show only that hidden text.

    I'm stuck because I need to get the color of the foreground and background of the font in my selection. Maybe the user is not using the normal Black on White combination...

     

    The simplier macro I was thinking is the following
    Public Sub MyHiddenText()
      With Selection
       .Font.UnderlineColor = .Font.Color
       .Font.Color = .ParagraphFormat.Shading.BackgroundPatternColor
       .Font.Underline = wdUnderlineDash
      End With
    End Sub
    
    

     

    But

    Selection.ParagraphFormat.Shading.BackgroundPatternColor<br/>
    
    

    reports the correct value only if to the paragraph was applied a background color, otherwise reports

    wdColorAutomatic -16777216 
    

    either if  the page is standard white, either if a color was applied to it.

     

    Similarly the propriety

    Selection.Font.Color is wdColorAutomatic -16777216 
    
    If no font color formatting was done and when is passed to
     Selection.Font.UnderlineColor
    

    the underline don't show.

    Could you please help me with that?

    Thanks, Lauro

     

    Wednesday, January 19, 2011 10:06 PM
  • If your 'hidden' text is only supposed to be viewable via the macro and not printable, why is it in the body of the document at all? Why not simply display a message box with the 'hidden' information?

    Alternatively, you could have custom document property to toggle the display state of the contents of an IF field, coded along the lines of:
    {IF{DOCPROPERTY ShowText}= 1 "Text to Display" "______"}
    where 'ShowText' is the name of your custom document property and you macro sets this to 1 or 0, following which you execute the command:
    ActiveDocument.Fields.Update


    Cheers
    Paul Edstein
    [MS MVP - Word]
    Thursday, January 20, 2011 1:18 AM
  • Dear Paul,

          my "hidden text" can be seen on the screen and can be printed, but only if the user wants so.  Moreover for my goals it must be inside the document and not in a message.

        As a small improvement of my previous routine I wrote this:

    Public Sub NewMyHiddenText()
    Dim backColor As Long, foreColor As Long
    
      With Selection
       foreColor = .Font.Color
       backColor = .ParagraphFormat.Shading.BackgroundPatternColor
       If foreColor = wdColorAutomatic Then foreColor = wdColorBlack
       If backColor = wdColorAutomatic Then backColor = wdColorWhite
       .Font.UnderlineColor = foreColor
       .Font.Color = backColor
       .Font.Underline = wdUnderlineDash
      End With
    End Sub
    
     

    It works if the font or paragraph were color formatted, but doesn't work if the color of the page was changed.

    Beside I don't know if I have to take care of other situations.

    Ciao Lauro
    Thursday, January 20, 2011 8:11 AM
  • Hi Lauro,

    If you take alternative the field-code approach I suggested, there'll be no font issues to worry about.


    Cheers
    Paul Edstein
    [MS MVP - Word]
    Thursday, January 20, 2011 10:29 AM