I seem to have a situation where the Edit/Find function won’t locate hidden text in (apparently) a particular document or kind of document. Here are the specifics. (I’m sure this will be like taking my car to the mechanic, but I’m going to give it a shot anyway!) We create a type of document in either English or Japanese. Both of them contain “author text,” which is text intended for the auhor’s edification but which should ultimately be removed. This text is formatted Hidden and Blue. To remove the text, I wrote what would seem to be a VERY simply routine that I’ve used a thousand times. It uses Find/Replace. I tried using just the Find and then deleting the Found range, but the problem apparently is that it can’t FIND anything to delete! Here is the code:
Sub RemoveHiddenText()
If MsgBox(“Are you sure you want to remove all hidden Author Notes?”, vbQuestion + vbOKCancel, “Remove Author Notes”) = vbOK Then
With ActiveDocument.Content.Find
.ClearFormatting
.Replacement.ClearFormatting
.Format = True
.Font.Hidden = True
.Font.Color = wdColorBlue
.Execute replacewith:=””, Replace:=wdReplaceAll
End With
End If
End Sub
I even cleared the formatting arguments, even though I understand that this is not (was not?) a “sticky” setting when using the Range object. Yet if I launch Word and immediately open a document written by our Japanese partners, the code (almost inevitably) fails to work; it can’t find the hidden text, let alone replace it. It also seems to inevitably fail if I then try it on an English document during the same Word session. BUT if I launch Word and then immediately open a document in English, it WILL work; and if I then open the Japanese document (in the same Word session,) then it seems always to work in THAT document, too!
I know that things that “usually” work or don’t work are the hardest to troubleshoot, but I was hoping that someone may have had a similar experience, and could perhaps steer me towards a solution or an explanation. I am attaching an edited version of the document here so that you can test it. (Remember it fails to work only if the Japanese document is the first document you try it on during that Word session.) I prefer to avoid using the Selection object (the Range object is more graceful), but I’m prepared to switch to that, if necessary. (Note that as I prepare to post this message, I did another test to guarantee that I was able to duplicate the problem, and of course, it seems to work flawlessly. Nonetheless, if I don’t post this, it will cease to work tomorrow and I’ll have to start all over again! Please HELP!)