Results 1 to 4 of 4
  1. #1
    New Lounger
    Join Date
    Mar 2002
    Location
    Connecticut, USA
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Reset Find Options (VBA/Word/2000)

    Hi All,

    I have some macros that do various Finds and Replaces (with and without formatting).

    I would like the Find and Replace dialog to return to the state they were in before the user ran my macros.

    Many articles show code routines like this one:

    http://www.mvps.org/word/FAQs/MacrosVBA/ClearFind.htm

    But this example just returns the Find parameters to nothing. It seems more user friendly to return them to the state they were in before the user ran the macro.

    Here is what I've tried so far:

    Public Sub FindNextAzimuth()
    Dim InitialFind As Find
    Set InitialFind = GetCurrentFindOptions()
    StandardFind Selection.Find, "AZIMUTH", wdFindAsk, True
    ResetFind InitialFind
    End Sub

    Function GetCurrentFindOptions() As Find
    Dim f As Find
    Set f = Selection.Find
    With Selection.Find
    f.Text = .Text
    f.MatchCase = .MatchCase
    If .Style <> "" Then
    f.Style = .Style
    End If
    f.ParagraphFormat = .ParagraphFormat
    f.Font = .Font
    f.Format = .Format
    f.Forward = .Forward
    f.Highlight = .Highlight
    f.MatchAllWordForms = .MatchAllWordForms
    f.MatchSoundsLike = .MatchSoundsLike
    f.MatchWholeWord = .MatchWholeWord
    f.MatchWildcards = .MatchWildcards
    f.Wrap = .Wrap
    With .Replacement
    f.Replacement.Text = .Text
    If .Style <> "" Then
    f.Replacement.Style = .Style
    End If
    f.Replacement.ParagraphFormat = .ParagraphFormat
    f.Replacement.Font = .Font
    f.Replacement.Highlight = .Highlight
    End With
    End With
    Set GetCurrentFindOptions = f
    End Function

    Sub ResetFind(oInitial As Find)
    With Selection.Find
    .Text = oInitial.Text
    .MatchCase = oInitial.MatchCase
    If oInitial.Style <> "" Then
    .Style = oInitial.Style
    End If
    .ParagraphFormat = oInitial.ParagraphFormat
    .Font = oInitial.Font
    .Format = oInitial.Format
    .Forward = oInitial.Forward
    .Highlight = oInitial.Highlight
    .MatchAllWordForms = oInitial.MatchAllWordForms
    .MatchSoundsLike = oInitial.MatchSoundsLike
    .MatchWholeWord = oInitial.MatchWholeWord
    .MatchWildcards = oInitial.MatchWildcards
    .Wrap = oInitial.Wrap
    With .Replacement
    .Text = oInitial.Replacement.Text
    If oInitial.Replacement.Style <> "" Then
    .Style = oInitial.Replacement.Style
    End If
    .ParagraphFormat = oInitial.Replacement.ParagraphFormat
    .Font = oInitial.Replacement.Font
    .Highlight = oInitial.Replacement.Highlight
    End With
    End With
    End Sub

    But of course the variable I'm using is just an object (reference) variable so I'm not really getting a copy of the settings - merely a pointer to the Selection.Find object.

    Anyone know a good way to do this?

  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Reset Find Options (VBA/Word/2000)

    You might be stuck having to gather all values into an external file (.ini, for example) and read the values back in at the end of your FindNextAzimuth.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  3. #3
    New Lounger
    Join Date
    Mar 2002
    Location
    Connecticut, USA
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Reset Find Options (VBA/Word/2000)

    Ouch!

    I was thinking of this, but then I remembered that I'd have to do that for the Font object, ParagraphFormat object, and Style object (for both the find and replace) as well. How tedious.

    Oh well.

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

    Re: Reset Find Options (VBA/Word/2000)

    It's not that bad.

    You can remember the values of a Font or Format object with
    <pre> set fontSaved = .Find.Font.Duplicate
    set formatSaved = .Find.ParagraphFormat.Duplicate
    </pre>

    But you need to watch Format.Shading which is a pointer to a shading object and isn't stored in the Format object itself.
    <pre> shadSaved.ForegroundPatternColor = .Find.ParagraphFormat.ForegroundPatternColor
    </pre>

    etc.

    StuartR

Posting Permissions

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