• Way to reset Range.Find.Style? (Office XP SP-2)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Way to reset Range.Find.Style? (Office XP SP-2)

    Author
    Topic
    #418984

    I’d like to take a Range.Find object and reset its .Style property to an empty string while retaining any other property settings that may be in effect (which rules out .ClearFormatting). The .Find.Style property for a fresh Range is an empty string (or at least .Find.Style = “” evaluates to True), but none of the following lines seems to work. (They all trigger errors along the lines of “Item with specified name doesn’t exist” or “Subscript out of range.”)

    rngX.Find.Style = “”
    rngX.Find.Style = vbNullString
    rngX.Find.Style = 0
    rngX.Find.Style = Nothing
    rngX.Find.Style = Empty
    rngX.Find.Style.Reset

    This 2-line variation also fails:

    Selection.Find.ClearFormatting
    rngX.Find.Style = Selection.Find.Style

    Adding the word Set also fails. (“Object required.”)

    Anybody know how to reset a .Find.Style?

    An unattractive workaround may be to create a new range and set all its properties (other than .Find.Style) to match those of the existing range. Avoiding this would be a good thing.

    Viewing 0 reply threads
    Author
    Replies
    • #944645

      Attempting to do this using the Macro recorder offered the syntax…

      .Find.Style = ActiveDocument.Styles("")

      Does it work for you?

      StuartR

      • #944648

        Nope. I get “5941: The requested member of the collection does not exist.”

        If it works for you, are you using Word 2003?

        • #944649

          > If it works for you, are you using Word 2003?

          ‘fraid so sad

          StuartR

          • #944659

            I have tentatively concluded that the solution for users of Word 2002 SP-2 looks like this:

                rngX.Find.Style = -112

            or this:

                rngX.Find.Style = -156

            or any value in between (seemingly a range of negative numbers reserved for built-in styles that Redmond has yet to construct).

            It doesn’t technically reset .Find.Style to an empty string, but the effect appears to be the same.

            LATER CORRECTION: -112 through -156 are actually the built-in Table Styles, but since they’re not searchable, applying them to a .Find.Style or .Find.Replacement.Style is, at least for some purposes, equivalent to resetting the Style property to an empty string.

    Viewing 0 reply threads
    Reply To: Way to reset Range.Find.Style? (Office XP SP-2)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: