Search Based on Font

User avatar
BobH
UraniumLounger
Posts: 9218
Joined: 13 Feb 2010, 01:27
Location: Deep in the Heart of Texas

Search Based on Font

Post by BobH »

Is it possible to search in Word for phrases based on their font, without VBA?

I want to search a document and extract what are ostensibly titles but not so identified in Word. When I find them, I want to copy and paste them into a different document with each title phrase on its on line. IOW I also want the para marker for each phrase.

:cheers: :chocciebar: :thankyou:
Bob's yer Uncle
(1/2)(1+√5)
Intel Core i5, 3570K, 3.40 GHz, 16 GB RAM, ECS Z77 H2-A3 Mobo, Windows 10 >HPE 64-bit, MS Office 2016

User avatar
HansV
Administrator
Posts: 78237
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Search Based on Font

Post by HansV »

Activate the Find tab of the Find and Replace dialog.
Leave the 'Find what' box empty.
Click 'More >>' to display the extra options.
Select Font ...from the Format... dropdown near the bottom of the dialog.

S0880.png

Select the font name you're searching for, and only if necessary other characteristics such as size, style and color.

S0881.png

Click OK.
Click 'Find Next'.

S0882.png
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

User avatar
BobH
UraniumLounger
Posts: 9218
Joined: 13 Feb 2010, 01:27
Location: Deep in the Heart of Texas

Re: Search Based on Font

Post by BobH »

Thank you, Hans.

The process is working; however, when I find an instance and click on the found text which is highlighted and try to copy and paste it, nothing happens.

The document contains copious instances of the font. Is there a way to find all of them at once before copying and pasting?

:cheers: :chocciebar: :thankyou:
Bob's yer Uncle
(1/2)(1+√5)
Intel Core i5, 3570K, 3.40 GHz, 16 GB RAM, ECS Z77 H2-A3 Mobo, Windows 10 >HPE 64-bit, MS Office 2016

User avatar
HansV
Administrator
Posts: 78237
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Search Based on Font

Post by HansV »

To select and copy them all in one go would require a macro.
You can select Reading Highlight > Highlight All in the dialog; this will highlight (but not select) all instances.
Best wishes,
Hans

User avatar
Charles Kenyon
4StarLounger
Posts: 596
Joined: 10 Jan 2016, 15:56
Location: Madison, Wisconsin

Re: Search Based on Font

Post by Charles Kenyon »

BobH wrote:
15 Nov 2021, 21:30
Thank you, Hans.

The process is working; however, when I find an instance and click on the found text which is highlighted and try to copy and paste it, nothing happens.

The document contains copious instances of the font. Is there a way to find all of them at once before copying and pasting?

:cheers: :chocciebar: :thankyou:
To clarify: The change you see in the text for found text in this process is not selecting it. It is something like temporary highlighting. Thus there is nothing selected to copy.

User avatar
Jay Freedman
Microsoft MVP
Posts: 1313
Joined: 24 May 2013, 15:33
Location: Warminster, PA

Re: Search Based on Font

Post by Jay Freedman »

Instead of clicking the Reading Highlight button, click the Find In button next to it. In the dropdown from that button, click Main Document. That does select -- rather than highlight -- all the found instances in the main document (not headers/footers [but there's a separate choice for that], text boxes, footnotes/endnotes, or anything else not in the main story range). Then copy/paste will work.

User avatar
HansV
Administrator
Posts: 78237
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Search Based on Font

Post by HansV »

Thanks, Charles - I never knew that! :thumbup:
Best wishes,
Hans

User avatar
BobH
UraniumLounger
Posts: 9218
Joined: 13 Feb 2010, 01:27
Location: Deep in the Heart of Texas

Re: Search Based on Font

Post by BobH »

Thanks, Jay!!!

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?

:cheers: :chocciebar: :thankyou:
Bob's yer Uncle
(1/2)(1+√5)
Intel Core i5, 3570K, 3.40 GHz, 16 GB RAM, ECS Z77 H2-A3 Mobo, Windows 10 >HPE 64-bit, MS Office 2016

User avatar
Jay Freedman
Microsoft MVP
Posts: 1313
Joined: 24 May 2013, 15:33
Location: Warminster, PA

Re: Search Based on Font

Post by Jay Freedman »

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.
Last edited by Jay Freedman on 21 Nov 2021, 19:22, edited 1 time in total.

User avatar
BobH
UraniumLounger
Posts: 9218
Joined: 13 Feb 2010, 01:27
Location: Deep in the Heart of Texas

Re: Search Based on Font

Post by BobH »

:cheers: :chocciebar: :thankyou:
Bob's yer Uncle
(1/2)(1+√5)
Intel Core i5, 3570K, 3.40 GHz, 16 GB RAM, ECS Z77 H2-A3 Mobo, Windows 10 >HPE 64-bit, MS Office 2016