Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Font is not found in Word when searching with VBA

Status
Not open for further replies.

KenWK

Programmer
May 25, 2001
76
0
0
US
Greetings,

I posted this to Microsoft's forum ( and they're going to "try to internally report this issue." I'm hoping someone here as seen this and/or found a work-around.

Please know that this NOT specific to Arial, that is just an example.

We've written a macro that search and replaces a bunch of characters in 9 different fonts to other characters and fonts, and noticed that some of them were not getting done, yet the same character, within the same document, with the same font change WAS getting found. Stopping the macro after the search is loaded up using (for instance)
Code:
Selection.find.found.font.name="Arial"
I'm seeing that the find dialog is showing "(Default)" in front of the font name being searched, as in "(Default) Arial".

The problem seems to be with how the font change was instituted in the text being searched, though I can't determine what is different between one that gets found and one that does not. If I set the find menu manually (without a macro) the "(Default)" does NOT show in the font dialog and the font is found in all instances.

If I clear the formatting on text that is initially NOT getting found using "Clear Formatting" from the style pane, or Ctrl + Shift + N, or "Selection.Style = "Default Paragraph Font" in VBA, and re-institute the font change to the SAME font it gets found with the macro.

So, I need to either set the font dialog with VBA in a way that does NOT make it read "(Default)" in front of the font name (like when I manually set it), or I need to detect when font change has whatever aspect it has that it causing it to NOT be found, and fix it before searching and replacing.

Any help or insight would be GREATLY appreciated.

Ken
 
The problem here is almost certainly because of the difference between a manually applied font and a font applied via a style, particularly the Default Paragraph Font.

You best bet is to iterate through the styles to find all of those that contain the font you are looking for and then Find against that style. However I wouldn't necessarily recommend this since we can simply change style itself, rather than applying a manual font to the text (mainly because the whole thing will get into a bit of a mess)
 
There aren't any character styles applied to the text I'm dealing with but there DOES appear to be some sort of underlying/invisible character style thing going on.

I found no answers as to why any of this is occurring but I DID find that clearing the formatting with
Code:
Selection.Find.ClearFormatting
before setting the find font does NOT cause the "(Default)" to go in before the font name on the find dialog. This, as I mentioned in a previous post, makes it so that all instances of the font gets found.

Well, at least all the instances of the font changes I'm dealing with. As I can't determine what makes one instance of a font change get found when the "(Default)" is in there and one NOT get found, I can't possibly say whether there might be other font changes with whatever underlying/invisible "attributes" (for lack of a better word) there might be. Of course, this also coupled by what the heck does "(Default)" mean in this instance anyway!!

Thanks a bunch for replying!
Ken
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top