8

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 :(

Ammar
  • 485
  • 1
  • 5
  • 14
  • 2
    Good question, upvote, must be encouraged. – Siddharth Nov 20 '12 at 02:54
  • When I ran this same code (PPT 2010, Win7/64-bit) and used Simplified Arabic as the font name, it did apply the font to the text. Whether it works beyond that, I don't know, since I don't have Arabic installed as an editing language in either Windows or Office. I'm guessing that you'd need both, and would also want to set the text's language (after "With .TextFrame.TextRange" add ".LanguageID = msoLanguageIDArabic" – Steve Rindsberg Nov 20 '12 at 15:27
  • @Ammar is this solved already? if not please comment :) – bonCodigo Jan 22 '13 at 13:53

2 Answers2

2

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" 
Ammar
  • 485
  • 1
  • 5
  • 14
0

Here is a similar case and this solution was given for a Chinese Font :) and can be used for any given that you know the CharSet code as well as the supporting Font Name as not every font will have the support for all language charsets..

In your case you need to find the charset you would like to use for Arabic and the supportive Font Name (set it according to the following sample). You will see the results in the run time.

UserForm1.TextBox2.Font.Charset = 134    '--CHINESESIMPLIFIED_CHARSET
UserForm1.TextBox2.Font.Name = ChrW(&H5B8B) + ChrW(&H4F53) '-- 宋体 SimSun font

UserForm1.TextBox2.Text = ChrW(37446)
strTxt2 = UserForm1.TextBox2.Text
'notice that ChrW(9246) produces a different character in Chinese
UserForm1.TextBox2.Text = strTxt2 & " " & ChrW(9246)
Community
  • 1
  • 1
bonCodigo
  • 14,268
  • 1
  • 48
  • 91
  • Thanks for reply, but unfortunately you misunderstood my question. Displaying unicode characters in VBA editor is not by problem. The issue here is changing the font of a powerpoint textbox containing unicode text. I can change the font by gui in powerpoint, but for my application I have to do it in vba programatically. – Ammar Jan 24 '13 at 01:35
  • @Ammar have you tried to apply the above into the `powerpoint textbox` ? – bonCodigo Jan 24 '13 at 04:01
  • The above code can't be directly applied to ppt texbox. In ppt, the font is changed by modifying `someShape.TextFrame.TextRange.Font.Name` property. There are no user forms. I don't see how above code can be applied. As far as the name of font is concerned, the fonts I am trying to use, they already have english names like "Simplified Arabic", "Traditional Arabic" etc. – Ammar Jan 24 '13 at 12:40
  • PS. there is no relevant `Charset` property I could find in vba :( – Ammar Jan 24 '13 at 12:51