Microsoft Word: Change the font of characters that are not in the standard font

I am trying to use VBA in Microsoft Word to automate highly repetitive operations on large documents.

The situation is this: I have a technical text containing many special characters, for example. ❨ (U + 2768) and ❩ (U + 2769). The text is mainly typed in Cumbria, but some special characters are not found in this font. However, I really know that all the characters used in the document are present in DejaVu Sans Mono. Therefore, I would like all the characters to be in Cumbria, except for those that cannot be displayed in this font - the characters that I want to show in DejaVu Sans Mono.

In Microsoft Word 2007, I could easily achieve this with Ctrl + A, install the font in DejaVu Sans Mono, install the font in Cambria. A second font change will only change the font of those characters that can be displayed in Cumbria.

However, in Microsoft Word 2010 this does not seem to work. Each character receives a Cambria font, and instead of displaying characters not found in Cambria, a label symbol in the box is displayed.

To overcome this, I turned to VBA. It is very easy to change the font of a given character, for example.

Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting Selection.Find.Text = ChrW(10088) Selection.Find.Replacement.Text = ChrW(10088) Selection.Find.Replacement.Font.Name = "DejaVu Sans Mono" Selection.Find.Execute Replace:=wdReplaceAll 

However, it’s not too funny to write the above code for each character in (C (DejaVu) βˆ– C (Cambria)) ∩ C (Doc), where C (DejaVu), C (Cambria) and C (Doc) is the set of all characters in DejaVu Sans Mono, Cambria and my paper respectively.

Is there a (fairly easy) way to do this automatically? Of course, Microsoft Word knows which characters are in Cumbria and which are not. I want all instances of these characters not to be found in Cumbria to get the font DejaVu Sans Mono.

+4
source share
1 answer

I think this answer will help you achieve your goal: Script to change fonts in a Word document

+1
source

All Articles