0

I want to set English US as default language for all shapes on my slides.

It seems the object model for PPT has changed over the years because none of the >5 years old macros here 1, 2 work.

I get the error

Method or data member not found

when trying to set the language to a shape

currentShape.DefaultLanguageID = lang 

I'm using PowerPoint v16.98 (25060824) for MacOS

Here are two version of my macro:

Version 1

Sub SetLanguageForAllText()
    Dim sld As Slide
    Dim shp As Shape
    Dim master As Design
    Dim layout As Object
    Dim langID As MsoLanguageID
    Dim tr As TextRange
    Dim i As Integer

    langID = msoLanguageIDEnglishUS

    ' Update all normal slides
    For Each sld In ActivePresentation.Slides
        For Each shp In sld.Shapes
            If shp.HasTextFrame Then
                If shp.TextFrame.HasText Then
                    shp.TextFrame.TextRange.LanguageID = langID
                End If
            End If
        Next shp
    Next sld

    ' Update master slide text
    For Each master In ActivePresentation.Designs
        ' Master Shapes
        For Each shp In master.SlideMaster.Shapes
            If shp.HasTextFrame Then
                If shp.TextFrame.HasText Then
                    shp.TextFrame.TextRange.LanguageID = langID
                End If
            End If
        Next shp

        ' Layouts
        For Each layout In master.SlideMaster.CustomLayouts
            For Each shp In layout.Shapes
                If shp.HasTextFrame Then
                    If shp.TextFrame.HasText Then
                        shp.TextFrame.TextRange.LanguageID = langID
                    End If
                End If
            Next shp
        Next layout
    Next master

    MsgBox "Language set for all text to: " & langID, vbInformation
End Sub

Version 2

Sub SetDefaultLanguage()
    Dim sld As Slide
    Dim shp As Shape
    Dim tr As TextRange
    Dim i As Integer
    Dim langID As MsoLanguageID
    Dim master As Design
    Dim layout As Object

    langID = msoLanguageIDEnglishUS

    ' Loop through normal slides
    For Each sld In ActivePresentation.Slides
        For Each shp In sld.Shapes
            If shp.HasTextFrame Then
                If shp.TextFrame.HasText Then
                    Set tr = shp.TextFrame.TextRange
                    For i = 1 To tr.Runs.Count
                        tr.Runs(i).LanguageID = langID
                    Next i
                End If
            End If
        Next shp
    Next sld

    ' Loop through master slides and layouts
    For Each master In ActivePresentation.Designs
        For Each shp In master.SlideMaster.Shapes
            If shp.HasTextFrame Then
                If shp.TextFrame.HasText Then
                    Set tr = shp.TextFrame.TextRange
                    For i = 1 To tr.Runs.Count
                        tr.Runs(i).LanguageID = langID
                    Next i
                End If
            End If
        Next shp

        For Each layout In master.SlideMaster.CustomLayouts
            For Each shp In layout.Shapes
                If shp.HasTextFrame Then
                    If shp.TextFrame.HasText Then
                        Set tr = shp.TextFrame.TextRange
                        For i = 1 To tr.Runs.Count
                            tr.Runs(i).LanguageID = langID
                        Next i
                    End If
                End If
            Next shp
        Next layout
    Next master

    MsgBox "Language set to: " & langID, vbInformation
End Sub

enter image description here

enter image description here

7
  • You aren't using DefaultLanguageID in your code ... which, btw, compiles and runs under Windows. A TextRange has a LanguageID - as in your code. DefaultLanguageID is a property of the Presentation object --> ActivePresentation.DefaultLanguageID = msoLanguageIDEnglishUS Commented Jun 25 at 6:40
  • @Ike I update my question content. Now you can see the two version of my macro. I also added a better screenshot, there you can see that I get the same error TextRange.LanguageID. As you can see on the second screenshot, I get the same error for ActivePresentation.DefaultLanguageID = msoLanguageIDEnglishUS Commented Jun 25 at 13:30
  • Then I suppose that this is a Mac issue ... Commented Jun 25 at 13:41
  • 1
    Thanks for your time! I will try on a windows tomorrow Commented Jun 25 at 13:43
  • Try Dim langID as Long rather than as msoLanguageID. Commented Jun 25 at 13:48

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.