本文介绍了VBA Powerpoint 2013:更改演示语言,包括 SmartArt 对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到通过 VBA 脚本更改 Powerpoint 2013 中 SmartArt 对象中语言的方法.我见过 PowerPoint 2007 - 设置语言包含文本但不适用于 SmartArt 对象的表格、图表等.知道我怎么能做到这一点吗?非常感谢.

I can not find a way to change by VBA script the language in SmartArt objects in Powerpoint 2013.I've seen PowerPoint 2007 - Set language on tables, charts etc that contains text but it does not work for SmartArt objects.Any idea how I could do this?Many thanks.

推荐答案

这是代码我终于用更改语言包括SmartArts:

This is the code I finally use to change the language including SmartArts:

Sub SetLangUS()
  Call changeLanguage(ActivePresentation, "US")
End Sub

Sub SetLangDE()
  Call changeLanguage(ActivePresentation, "DE")
End Sub



Private Function changeLanguage(oPres As Presentation, langStr As String)
' Reference http://stackoverflow.com/questions/4735765/powerpoint-2007-set-language-on-tables-charts-etc-that-contains-text
' https://support.microsoft.com/en-us/kb/245468

    On Error Resume Next

    Dim r, c As Integer
    Dim oSlide As Slide
    Dim oNode As SmartArtNode
    Dim oShape, oNodeShape As Shape
    Dim lang As String

    'lang = "Norwegian"
    'Determine language selected
    If langStr = "US" Then
        lang = msoLanguageIDEnglishUS
    ElseIf langStr = "UK" Then
        lang = msoLanguageIDEnglishUK
    ElseIf langStr = "DE" Then
        lang = msoLanguageIDGerman
    ElseIf langStr = "FR" Then
        lang = msoLanguageIDFrench
    End If

    'Set default language in application
    oPres.DefaultLanguageID = lang

    'Set language in each textbox in each slide
    For Each oSlide In oPres.Slides
        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
            ElseIf oShape.HasSmartArt Then
                For Each oNode In oShape.SmartArt.AllNodes
                    oNode.TextFrame2.TextRange.LanguageID = lang
                Next
            Else
                oShape.TextFrame.TextRange.LanguageID = lang

                    For c = 0 To oShape.GroupItems.Count - 1
                        oShape.GroupItems(c).TextFrame.TextRange.LanguageID = lang
                    Next

            End If
        Next
    Next

    ' Update Masters
    For Each oShape In oPres.SlideMaster.Shapes
        oShape.TextFrame.TextRange.LanguageID = lang
    Next

    For Each oShape In oPres.TitleMaster.Shapes
        oShape.TextFrame.TextRange.LanguageID = lang
    Next

    For Each oShape In oPres.NotesMaster.Shapes
        oShape.TextFrame.TextRange.LanguageID = lang
    Next

    ' MsgBox
    MsgBox "Presentation Language was changed to " & langStr & ".", vbOKOnly, "SetLanguage"


End Function

这篇关于VBA Powerpoint 2013:更改演示语言,包括 SmartArt 对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 04:58