8

So I've got this macro that basically scans each slide in PowerPoint and sets the specified language. Works great. Howerver, it skips containers that aren't text boxes. I'd like it to apply the language on tables, smartart, charts etc. Basically anything that may contain text.

Is this even possible? This is the current code:

Public Sub changeLanguage()

    On Error Resume Next

    'lang = "English"
    lang = "Norwegian"

    'Determine language selected
    If lang = "English" Then
            lang = msoLanguageIDEnglishUK
    ElseIf lang = "Norwegian" Then
            lang = msoLanguageIDNorwegianBokmol
    End If

    'Set default language in application
    ActivePresentation.DefaultLanguageID = lang

    'Set language in each textbox in each slide
    For Each oSlide In ActivePresentation.Slides
        Dim oShape As Shape

        For Each oShape In oSlide.Shapes
            oShape.Select
            oShape.TextFrame.TextRange.LanguageID = lang
        Next
    Next

End Sub

3 Answers 3

9

Yeah, it's not all that intuitive in PowerPoint, but it can be done. Basically, there are 3 major types of shapes (simple, grouped and tables). This code will check them all:

Public Sub changeLanguage()
    On Error Resume Next
    Dim gi As GroupShapes '<-this was added. used below
    'lang = "English"
    lang = "Norwegian"
    'Determine language selected
    If lang = "English" Then
        lang = msoLanguageIDEnglishUK
    ElseIf lang = "Norwegian" Then
        lang = msoLanguageIDNorwegianBokmol
    End If
    'Set default language in application
    ActivePresentation.DefaultLanguageID = lang

    'Set language in each textbox in each slide
    For Each oSlide In ActivePresentation.Slides
        Dim oShape As Shape

        ' Sets the language for the notes page as well.
        Dim oShape As Shape
        For Each oShape In oSlide.NotesPage.Shapes
            oShape.Select
            oShape.TextFrame.TextRange.LanguageID = lang
        Next

        For Each oShape In oSlide.Shapes
            'Check first if it is a table
            If oShape.HasTable Then
                For r = 1 To oShape.Table.Rows.Count
                    For c = 1 To oShape.Table.Columns.Count
                    oShape.Table.Cell(r, c).Shape.TextFrame.TextRange.LanguageID = lang
                    Next
                Next
            Else
                Set gi = oShape.GroupItems
                'Check if it is a group of shapes
                If Not gi Is Nothing Then
                    If oShape.GroupItems.Count > 0 Then
                        For i = 0 To oShape.GroupItems.Count - 1
                            oShape.GroupItems(i).TextFrame.TextRange.LanguageID = lang
                        Next
                    End If
                'it's none of the above, it's just a simple shape, change the language ID
                Else
                    oShape.TextFrame.TextRange.LanguageID = lang
                End If
            End If
        Next
    Next
End Sub
10
  • It works pretty well! But it doesnt't seem to check SmartArt. Is this possible? Microsoft should have included Macro recording in the 2007 version so I could record clicking on a SmartArt object, figuring out which type it actually is. Commented Jan 20, 2011 at 6:49
  • It does check SmartArt on my side, but I tested on PowerPoint 2010. Even in 2007 though SmartArt is considered oShape.GroupItems. If you try testing it on a different deck with SmartArt do you get the same results?
    – Todd Main
    Commented Jan 20, 2011 at 7:37
  • @Kenny Bones: Have you been able to try this with a different deck?
    – Todd Main
    Commented Jan 30, 2011 at 21:53
  • Hi, ok I've done some testing now and I see that you're applying language to the SmartArt using oShape.GroupItems(i).TextFrame.TextRange.LanguageID. But I think this is where it all happens. I did a check to see if oShape is SmartArt and then I paused the macro and added a watch for oShape. And it there I found that language is set on GroupItems.Item 1.TextFrame.TextRange.LanguageID. But there's not LanguageID on GroupItems directly it seems. Commented Feb 9, 2011 at 13:49
  • @Kenny Bones: If you need it on GroupItems directly as well, just put oShape.TextFrame.TextRange.LanguageID = lang right below the line If Not gi Is Nothing Then.
    – Todd Main
    Commented Feb 10, 2011 at 23:27
1

Although a bit of time passed ... came here from https://superuser.com/questions/432366/how-do-i-change-the-language-of-all-powerpoint-slides-at-once. Since I prefer working with python, a python version using the win32com package would be:

infile_name = 'drive:/path/to/in.pptx'
outfile_name = 'drive:/path/to/out.pptx'

target_language = 1031 # find in language list, here German

import time
import win32com.client


ppt = win32com.client.Dispatch('PowerPoint.Application')
ppt.Visible = True

presentation = ppt.Presentations.Open(infile_name)

def change_all_subshapes(target_shape, language_id):
    if target_shape.HasTextFrame:
        target_shape.TextFrame.TextRange.languageID = language_id

    if target_shape.HasTable:
        for r in range(1, target_shape.Table.Rows.Count + 1):
            for c in range(1, target_shape.Table.Columns.Count + 1):
                target_shape.Table.Cell(r, c).Shape.TextFrame.TextRange.LanguageID = language_id

    # look the constants msoGroup and msoSmartArt up
    if target_shape.Type in [6, 24]:
        for i in range(1, target_shape.GroupItems.Count + 1):
            change_all_subshapes(target_shape.GroupItems.Item(i), language_id)

# necessary: hopefully ppt is open after a second
time.sleep(1)

print('all slides')
for i in range(1, presentation.Slides.Count + 1):
    for j in range(1, presentation.Slides(i).Shapes.Count + 1):
        change_all_subshapes(presentation.Slides(i).Shapes(j), target_language)

print('master shapes')
for i in range(1, presentation.SlideMaster.CustomLayouts.Count + 1):
    for j in range(1, presentation.SlideMaster.CustomLayouts(i).Shapes.Count + 1):
        change_all_subshapes(presentation.SlideMaster.CustomLayouts(i).Shapes(j), target_language)

presentation.SaveAs(outfile_name)
presentation.Close()
ppt.Quit()
0

I had the same problem when doing macro for changing language in all shapes. As far as I learned, in PPT2007 it is not possible to set language on the objects such as Charts and SmartArt, programatically. There is no access to set languageID in VBA on these objects. However, changing language by clicking on the SmartArt object or Chart object works.

For the other objects:

  • grouped items - I had to traverse programatically (as on example in Otaku's post) through all objects in a group to set a language
  • table - I traversed through all cells.

Not the answer you're looking for? Browse other questions tagged or ask your own question.