Results 1 to 5 of 5
  1. #1
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

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

    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.

  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

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

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

    <code>.Find.Style = ActiveDocument.Styles("")</code>

    Does it work for you?

    StuartR

  3. #3
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

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

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

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

  4. #4
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

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

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

    'fraid so <img src=/S/sad.gif border=0 alt=sad width=15 height=15>

    StuartR

  5. #5
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

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

    I have tentatively concluded that the solution for users of Word 2002 SP-2 looks like this:
    <pre> rngX.Find.Style = -112</pre>

    or this:
    <pre> rngX.Find.Style = -156</pre>

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •