Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change font of a Non-English TextBox

Please consider the following piece of code

With ActivePresentation
    Set sldNewSlide = .Slides.Add(.Slides.Count + 1, ppLayoutBlank)
    With sldNewSlide
    Set shpCurrShape = .Shapes.AddTextbox(msoTextOrientationHorizontal, 25, 50, 50, 200)

        With shpCurrShape
           With .TextFrame.TextRange

              '------------ Below is an ARABIC string
              .Text = ChrW$(&H6A9) & ChrW$(&H64A) & ChrW$(&H641) & " " & ChrW$(&H62D) & ChrW$(&H627) & ChrW$(&H644) & ChrW$(&H643)

              With .Font
                 .Name = "someFontName" '-------------- THIS LINE IS NOT WORKING
                 .Size = 65
              End With

           End With
        End With

    End With
End With

As indicated above, the font of arabic text is not being changed. Font change works well when the textbox contains english text. In case there is mixed arabic & english text, the english font is changed but arabic text stays in the default font (i.e Arial).

This code was working fine in Office 2003, but I came across this problem when trying to run in Office 2007/2010. I have double checked, the font I'm trying to specify is installed on the computer.

Although I have tested with arabic script languages only (arabic/urdu/persian etc), but I guess this problem will come up when dealing with any non-latin-script language.

Any suggestions? seems like a bug in later versions of ms office.

PS. setting the textbox language as suggested by @Steve (.LanguageID = msoLanguageIDArabic) has no effect :(

like image 446
Ammar Avatar asked Nov 20 '12 02:11

Ammar


1 Answers

I found the answer myself. There are different Name properties in the Font class for different scripts. Here is a list of all Font members. In my case, I had to use NameComplexScript property. Incorporating this change, the code works like a charm

.Font.NameComplexScript = "someFontName" 
like image 109
Ammar Avatar answered Oct 31 '22 03:10

Ammar