BobH wrote: ↑20 Nov 2021, 20:42
That worked a treat. Is it possible that Word creates a macro from that sequence of choices? Or, is there a way that I can create a macro that does that?
Well, sort of. The nasty trick that makes it work is the much-maligned SendKeys command, which simulates pressing keys in the dialog. This macro selects all text in the document that has a font size of 16 points.
Code: Select all
Sub Macro1()
With Dialogs(wdDialogEditFind)
.Format = True
.Find = ""
SendKeys "%oF%s16~%i~": .Display
End With
End Sub
The string in the SendKeys command "presses" the sequence Alt+o, F, Alt+s, 16, Enter, Alt+i, Enter. That opens the Format menu, selects the Font entry, selects the Size box, enters 16, clicks OK, selects the Find In button, and hits Enter -- exactly what you would do manually. The .Display command runs the dialog's code.
There are two problems with this. One is that the string has to be constructed specially for the exact formatting you want to find. Adding a userform to let you pick a format and convert that to the correct string would be a lot of work. The second problem is that the SendKeys command is much-maligned because it doesn't always work.
Another difficulty is this: Using the dialog manually, you can choose a style to search for, which would be preferable to searching for a specific direct formatting if the document uses styles as it should. However, the SendKeys string that ought to select a style from the secondary dialog fails miserably. Fortunately, the right-click menu in the Styles pane has a command to select all instances of the chosen style.