Consulting

Results 1 to 7 of 7

Thread: Change font of a Non-English TextBox

  1. #1
    VBAX Newbie
    Joined
    Nov 2012
    Posts
    3
    Location

    Change font of a Non-English TextBox

    Please consider the following piece of code
    [vba]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[/vba]
    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.

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    Seems to work ok for me (of course, I can't actually read it)


    [vba]
    Option Explicit
    Sub test()
    Dim sldNewSlide As Slide
    Dim shpCurrShape As Shape
    With ActivePresentation
    Set sldNewSlide = .Slides.Add(.Slides.Count + 1, ppLayoutBlank)
    With sldNewSlide
    ' original Set shpCurrShape = .Shapes.AddTextbox(msoTextOrientationHorizontal, 25, 50, 50, 200) 'left, top width height
    Set shpCurrShape = .Shapes.AddTextbox(msoTextOrientationHorizontal, 25, 50, 500, 50) 'left, top width height

    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 = "Arial Unicode MS" '-------------- seems to work with or with out a .Name
    .Size = 65
    End With

    End With
    End With

    End With
    End With
    End Sub
    [/vba]

    Paul
    Attached Images Attached Images

  3. #3
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    I see the same as Paul but I always get Arial whatever font I specify.
    Last edited by John Wilson; 11-27-2012 at 07:16 AM.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  4. #4
    VBAX Newbie
    Joined
    Nov 2012
    Posts
    3
    Location
    Thanks both for the replies.

    @Paul, No it is not working for you. Please place the cursor inside the textbox, and you will see the font still as default one (Arial). Had the font changed to "Arial Unicode MS", it would have looked like the attached image.
    Attached Images Attached Images

  5. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    Sorry I mis-understood --

    I believe that PP tries to do a font substatition if it needs / wants to, especially for the higher order unicode characters

    In 2007, in the [Design] tab, [Themes], [Fonts] you can create a new theme and use that.

    In the screen shot, the 'English' is in Bookman, but the Arabic is in Arial Unicode

    Maybe that'll help??? The addition of 'Themes' with Office 2007 might be the reason there's a difference from your working 2003 version

    [vba]
    Option Explicit
    Sub test()
    Dim sldNewSlide As Slide
    Dim shpCurrShape As Shape
    With ActivePresentation
    Set sldNewSlide = .Slides.Add(.Slides.Count + 1, ppLayoutBlank)
    With sldNewSlide

    Set shpCurrShape = .Shapes.AddTextbox(msoTextOrientationHorizontal, 25, 50, 500, 50) 'left, top width height

    With shpCurrShape
    With .TextFrame.TextRange

    With .Font
    .Name = "Bookman Old Style"
    .Size = 65
    End With

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


    End With
    End With

    End With
    End With
    End Sub
    [/vba]

    Paul
    Attached Images Attached Images

  6. #6
    VBAX Newbie
    Joined
    Nov 2012
    Posts
    3
    Location
    Bumping up this thread because I found solution to my problem.

    There are different Name properties in the Font class for different scripts. In my case, I had to use NameComplexScript property.

    The portion of code that didn't work, should be like this
    [vba]With .Font
    .NameComplexScript = "Arial Unicode MS"
    .Size = 65
    End With[/vba]
    Here is a list of all Font members: http ://goo.gl/1qkM3 [sorry, can't post full links]

  7. #7
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    Thanks for posting the solution

    Paul

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •