Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-12-2021, 05:38 AM
kae0088 kae0088 is offline Searching font names Windows 7 64bit Searching font names Office 2010 32bit
Novice
Searching font names
 
Join Date: May 2012
Location: Melbourne, Australia
Posts: 20
kae0088 is on a distinguished road
Default Searching font names

When I look at font names they sometimes have a prefix or suffix such as “Cambria (Heading)”, “(Body) Calibri” or “(Default) Times New Roman”.



I want to search for text with specific fonts in VBA but while I can search for the font name such as Calibri but it will not find text with the font “(Body) Calibri”, nor can I find it by setting sFontName = "(Body) Calibri". How can I find these fonts
My code is:

sFontName = "Calibri"
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Replacement.Text = ""
.Format = True
.Text = ""
.Font.Name = sFontName
.Execute
End With
Reply With Quote
  #2  
Old 11-12-2021, 06:40 AM
scienceguy scienceguy is offline Searching font names Windows 10 Searching font names Office 2016
Advanced Beginner
 
Join Date: Feb 2019
Posts: 46
scienceguy is on a distinguished road
Default

Hi kae0088,

I don't know if this helps or not, but I did a very simple routine in order to return the font name of each paragraph in the document (code is below). For the first paragraph, I formatted "Calibri (Body)" and the second paragraph was just "Calibri". When I ran the code, the font returned was "Calibri" for both paragraphs.

Perhaps, there is no difference?

Roy


Code:
Sub findme2()

    Dim oParagraph As Paragraph
    For Each oParagraph In ActiveDocument.Paragraphs
        
        MsgBox oParagraph.Range.Font.Name
        
    Next

End Sub
Reply With Quote
  #3  
Old 11-12-2021, 05:03 PM
kae0088 kae0088 is offline Searching font names Windows 7 64bit Searching font names Office 2010 32bit
Novice
Searching font names
 
Join Date: May 2012
Location: Melbourne, Australia
Posts: 20
kae0088 is on a distinguished road
Default

Hi scienceguy


If you execute:
then the font name will change from "Calibri (Body)" to "Calibri"




There is an interaction with Office Find & Replace (CTRL+H).
If you execute:
Code:
Sub SetFontName()
 Selection.Find.ClearFormatting
 Selection.Find.Font.Name = "Calibri"
 Selection.Find.Execute
End Sub
then it doesn't find text with "Calibri (Body)"but F&R now has under "Find what:" the Format font "(Default) Calibri". F&R will now find "Calibri" but not "Calibri (Body".


It all doesn't help me with my task.
Reply With Quote
  #4  
Old 11-12-2021, 06:47 PM
Guessed's Avatar
Guessed Guessed is offline Searching font names Windows 10 Searching font names Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,966
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

The font described by the theme's minor font (in your case Calibri (Body)) can be found by searching for a font by the name of "+Body"
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 11-12-2021, 07:02 PM
kae0088 kae0088 is offline Searching font names Windows 7 64bit Searching font names Office 2010 32bit
Novice
Searching font names
 
Join Date: May 2012
Location: Melbourne, Australia
Posts: 20
kae0088 is on a distinguished road
Default

Thanks. I am now getting somewhere. I can search for "+Headings" and "+Body" and determine the font from the found text.
Reply With Quote
  #6  
Old 11-12-2021, 09:02 PM
kae0088 kae0088 is offline Searching font names Windows 7 64bit Searching font names Office 2010 32bit
Novice
Searching font names
 
Join Date: May 2012
Location: Melbourne, Australia
Posts: 20
kae0088 is on a distinguished road
Default

Having resolved the problem with (Body) and (Headings) suffixes there is still the problem of (Default) prefix as in “(Default) Times New Roman”.
If I run
Code:
Sub FindFontName()
    Selection.Find.ClearFormatting
    Selection.Find.Font.Name = "Times New Roman"
    Selection.Find.Execute
  End Sub
it won’t find “(Default) Times New Roman” fonts. But the following steps will:
1. In F&R click No Formatting then add the font “Times New Roman”
2. In F&R click Find Next to find at least one instance of the font.
3. Now the following VBA macro will find both “Times New Roman” and “(Default) Times New Roman”.
Code:
Sub FindFontName()
    Selection.Find.Execute
  End Sub

Any views on how I can resolve the issue of the (Default) prefix.
Reply With Quote
  #7  
Old 11-13-2021, 07:40 PM
Guessed's Avatar
Guessed Guessed is offline Searching font names Windows 10 Searching font names Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,966
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Can you post a sample document that shows this Default font? I don't recall ever seeing this and I haven't played with default fonts as I define typefaces for all my styles (usually with the theme fonts).
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #8  
Old 11-13-2021, 11:28 PM
kae0088 kae0088 is offline Searching font names Windows 7 64bit Searching font names Office 2010 32bit
Novice
Searching font names
 
Join Date: May 2012
Location: Melbourne, Australia
Posts: 20
kae0088 is on a distinguished road
Default

Run these steps in order.

1. Run the macro in the attached document and it will find the last paragraph but not the earlier paragraphs that supposedly have the same font.


2. Now open F&R and without changing anything click find. It will also find only the last paragraph.



3. In F&R with the cursor in Find What, click No Formatting then Format > Font > Times New Roman. F&R will now find all paragraphs.


4. In the macro comment out the first three statements leaving only

If Not Selection.Find.Execute Then MsgBox "Not found"
The macro will now find all paragraphs.


5. Select one of the earlier paragraphs and re-apply Times New Roman. Now run the steps again.
Attached Files
File Type: docm Testing Times New Roman.docm (20.1 KB, 5 views)
Reply With Quote
  #9  
Old 11-17-2021, 05:34 AM
kae0088 kae0088 is offline Searching font names Windows 7 64bit Searching font names Office 2010 32bit
Novice
Searching font names
 
Join Date: May 2012
Location: Melbourne, Australia
Posts: 20
kae0088 is on a distinguished road
Default

Did the file arrive unscathed?

I still can't resolve mt problem.
Reply With Quote
  #10  
Old 11-17-2021, 01:25 PM
Guessed's Avatar
Guessed Guessed is offline Searching font names Windows 10 Searching font names Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,966
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Yes, I downloaded the file and can verify that your described steps gave me the same result as you got.

I don't have a solution for this issue at the moment and haven't got a great deal of time to fiddle with it. I will try to get back onto looking at this on the weekend but someone else may be able to step with a suggestion in the meantime.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
Reply

Tags
vba find and replace

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Searching font names General Question on List of Font Names SamDsouza Word VBA 10 02-28-2021 07:24 PM
Searching font names Would like to shortern the coding for searching docx file names in specific directory SamDsouza Word VBA 4 01-06-2021 07:27 AM
Macro for Font Names and Sizes apollox Word VBA 8 06-13-2018 06:00 AM
Formula for searching names in one go SilverChat Excel 2 05-07-2018 06:11 PM
How to enter names in Resource Pool/names pstein Project 1 03-26-2012 07:37 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:12 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft