Consulting

Results 1 to 6 of 6

Thread: Open EditReplace dialog with Wild card selected from macro

  1. #1
    VBAX Regular
    Joined
    Feb 2020
    Location
    Auckland, NZ
    Posts
    28
    Location

    Open EditReplace dialog with Wild card selected from macro

    Is there a way to open the Find/Replace dialog such that the Wild Card option is selected?

    I have got it to open with the Find box populated with the contents of a selection, as follows.

    Sub WildCardFind()
    ' Paul Beverley - Version 22.02.11
    ' Call up Advanced Find dialog box
    ' 7/7/2021 CG modification: set the dialog to Wild Card search, and populate Find box with the selected text
    
    
    Dim rSelect As Range
    Dim sSelect As String
    
    
    Set rSelect = Selection.Range
    sSelect = rSelect.Text
    
    
    Selection.TypeText "DONE"
    
    
        With Dialogs(wdDialogEditReplace)
            .Find = sSelect
                With Selection.Find
                    .MatchWildcards = True
                End With
            .Show
        End With
        
    End Sub
    I just haven't been able to track down a solution to this anywhere.

    Thanks.

  2. #2
    If you know what you want to find, and what you want to replace it with, why bother to open the dialog? You can just run the replacement in VBA.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Regular
    Joined
    Feb 2020
    Location
    Auckland, NZ
    Posts
    28
    Location
    I don't want to fill this thread with unnecessary explanations, but it does need to be the way I described.

  4. #4
    VBAX Regular
    Joined
    Jul 2020
    Location
    Sun Prairie
    Posts
    39
    Location
    Look into the (flaky) sendkeys. See https://answers.microsoft.com/en-us/...4-baf3fd37678d

  5. #5
    VBAX Regular
    Joined
    Jul 2020
    Location
    Sun Prairie
    Posts
    39
    Location
    Look into the (flaky) sendkeys. See https://answers.microsoft.com/en-us/...4-baf3fd37678d

  6. #6
    VBAX Regular
    Joined
    Feb 2020
    Location
    Auckland, NZ
    Posts
    28
    Location
    Hi Chas, thanks for that suggestion.
    I've played around with it quite a bit. The best I got was focus on "Use wildcard", but not a check in the box.
    One thing led to another, and I reversed the order of some of the existing code, as follows:
            .Show
            With Selection.Find
                .MatchWildcards = True
            End With
    That got me most of the way, but only on the second time opening the dialog, after manually selecting "More" to expand it on first opening.
    So far I haven't succeeded in using SendKeys to open it in expanded mode the first time.

Posting Permissions

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