Search code examples
vbafontsms-wordnon-english

How can I change the font size of non-English words?


In a Word 2007 document, I manually select a sentence containing both English and Bengali words of multiple font sizes. When I enter some numeric value in the Font size list-box in the panel and press Enter, the whole sentence font size is changed (including Bengali words).

When I select the same sentence in a Word-VBA macro and in final line try

Selection.font.Size = 8

only English words' font size gets changed.

  • I tried to loop through each character, but I got the same result.
  • I need to stick to Word-VBA as it is part of a web scraping program using Chrome web-driver Selenium.
  • I tried a simple macro in a manually-created Word document with manually typed mixed English and Bengali words with the Vrinda (Body CS) font and the result was the same. The whole sentence is selected, but only English words' fonts get changed.

Sample Text "I am Ok You are Ok আমিও ঠিক তুমিও ঠিক Is it ok"


Solution

  • Word differentiates between text formatted as left-to-right (LTR) and text formatted as right-to-left (RTL). I'm not familiar with written (or spoken) Bengali, but Word apparently considers it to be RTL. In the object model (VBA) there's a separate set of Font properties for RTL - the suffix Bi is added to the property name. So

    Selection.Font.Size = 8
    Selection.Font.SizeBi = 8
    

    Should take care of both languages.