Search for text, replace it with hidden text RRS feed

  • Question

  • I am running word 2010.  I am trying to write a macro which finds all instances of the word 'john' and replaces it with 'john' but with that text hidden.  I cant seem to get this working.
    Sunday, August 7, 2011 2:59 AM

All replies

  • Hi


    Here is a hint:


    Sub Hide_John()
      Selection.HomeKey wdStory, wdMove
      Selection.Find.Replacement.Font.Hidden = True
      With Selection.Find
        .Text = "John"
        .Replacement.Text = "John"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = True
        .MatchWholeWord = True
      End With
      Selection.Find.Execute Replace:=wdReplaceAll
    End Sub

    This is a simple replace. You can also traverse the entire document, find the text and set the font of selection to be Hidden



    • Proposed as answer by Shasur Tuesday, August 30, 2011 9:44 AM
    Sunday, August 7, 2011 6:17 AM
  • Thanks for your help here.  I tried the above code, it works in that it replaces 'John' with 'Jonn' (I tested it by changing the replace text to 'JohnX' and it turned all the Johns to' JohnX'), however the text is still visible - maybe there is a setting somewhere else whereby the hidden text does not get hidden....
    Sunday, August 7, 2011 7:36 AM
  • Hi

    I think the Hidden text might be made visible in the setttings - the Hiddent text, however will be underlined with dots


    You can change the settings as shown below


    Sunday, August 7, 2011 3:59 PM
  • Sorry I dont follow - 'you can change the settings as shown below' - where exactly, I couldn't find any reference  on your two websites - is that what you meant? 


    Have you tested the above code to see if it does make the replaced text hidden?


    I wonder if there is just a general bug in VBA where it can't make text hidden.

    Sunday, August 7, 2011 11:32 PM
  • Hi

    The image was not rendered correctly. Please check i
    • Proposed as answer by Shasur Tuesday, August 30, 2011 9:44 AM
    Monday, August 8, 2011 2:51 AM
  • Ok great, tested and it works.
    Tuesday, August 9, 2011 11:48 AM