PDA

View Full Version : Open EditReplace dialog with Wild card selected from macro



Walentyn
07-06-2021, 07:39 PM
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.

gmayor
07-06-2021, 10:29 PM
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.

Walentyn
07-07-2021, 11:18 AM
I don't want to fill this thread with unnecessary explanations, but it does need to be the way I described.

Chas Kenyon
07-09-2021, 04:51 AM
Look into the (flaky) sendkeys. See https://answers.microsoft.com/en-us/msoffice/forum/all/intercept-ctrlf-to-run-macro-rather-than-show/c591c726-84b6-4fde-9814-baf3fd37678d

Chas Kenyon
07-09-2021, 08:28 AM
Look into the (flaky) sendkeys. See https://answers.microsoft.com/en-us/msoffice/forum/all/intercept-ctrlf-to-run-macro-rather-than-show/c591c726-84b6-4fde-9814-baf3fd37678d

Walentyn
07-11-2021, 05:35 PM
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.