Search in Word is hanging within a content control RRS feed

  • Question

  • Hello everybody

    I have a strange problem with my search sub. I'm searching for abbreviations, that means words of two or more capital letters.

    If I have no content controls (cc) in my document it works perfectly. Simple cc's work as well but one text cc with "TT.MM.JJJJ" makes problems: Word doesn't jump to the next abbreviation with find.execute.

    Here my code:

    Dim rngAbbreviation as Range
    Dim strAbbreviation as String

    Selection.HomeKey Unit:=wdStory With Selection.Find .ClearFormatting .Text = "<[A-Z]{2;5}" .MatchWildcards = True .Wrap = wdFindContinue .Forward = True .MatchWholeWord = True Do While .Execute = True If Not Selection.Information(wdInContentControl) Then Set rngAbbreviation = ActiveDocument.Range(Start:=Selection.Start, End:=Selection.End) strAbbreviation = rngAbbreviation.Text Debug.Print strAbbreviation End If Loop End With

    As you can see I tried to test if the found text is within a cc, but this seems not to be the problem. The problem is that with .Execute no next abbreviation will be found. The loop remains within this cc.

    Does anybody have an idea whats wrong?

    Thanks a lot


    • Edited by Daniel722 Tuesday, August 28, 2018 7:38 AM orthos
    Tuesday, August 28, 2018 7:37 AM

All replies

  • I tried to replicate this but could not (using "," instead of ";" and DD.MM.YYYY instead of TT.MM.JJJJ on a system configured for UK English).

    Can you reduce and anonymise your problem document and post it somewhere reachable online (e.g. dropbox etc.)?

    Also, which versions of Windows and Word?

    Peter Jamieson

    Tuesday, August 28, 2018 4:34 PM
  • Hi Peter

    thanks for your help and sorry for the delay.

    Here you can download the document:

    It has three buttons in the ribbon (Start). Pressing "Abkürzungen suchen" runs the procedure "pSearchForAll" in the module "Allgemein".

    The procedure hangs in the last content control (red font).

    Thanks a lot and best wishes


    Sunday, September 9, 2018 4:25 PM
  • I had a quick look.

    What seems to make the difference is the value of the ShowingPlaceholderText property of the COntent Control. It corresponds to a <w:showingPlcHdr/> element in the document's XML. Some of the other content controls also have this property set to True but I suspect that they behave differently because there is only one abbreviation in each of them.

    However at present I cannot see a simple way to deal with this in the VBA because it is a read-only property.

    Peter Jamieson

    Sunday, September 9, 2018 5:47 PM
  • Hi Peter

    thanks for your help.

    Hehe, I found an easy way, because no abbreviation should be within the cc (my customer promised;-)).

    So in the IF I added an ELSE with:

        Selection.MoveRight Unit:=wdCharacter, Count:=1
    I think this way he will be happy.

    Thanks and best wishes


    Tuesday, September 11, 2018 3:18 PM