2016-06-06 4 views

Répondre

0

C'est le code j'utilise enfin changer la langue, y compris 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 
1

Vous devez accéder aux nœuds (ou GroupItems) de l'objet SmartArt comme ceci:

Sub SwitchSmartArtLanguage(oSA As SmartArt) 
    Dim oNode As SmartArtNode 
    With oSA 
    For Each oNode In .Nodes 
     oNode.TextFrame2.TextRange.LanguageID = msoLanguageIDEnglishUK 
    Next 
    End With 
End Sub 
+0

D'une certaine façon, il ne fonctionne pas. Comment êtes-vous arrivé à TextFrame2 au lieu de TextFrame pour les formes normales? Aurais-je besoin de recurse à travers les nœuds? Je posterai mon code plus tard. –

+0

Étrange. Cela a fonctionné dans mon deck de test. J'utilise TextFrame2 (et TextRange2 et diverses autres API V2) car ils ajoutent plus de propriétés aux objets depuis Office 2007 et comme vous avez mentionné que vous utilisez 2013, il est logique d'utiliser la dernière API. Oui, vous devez parcourir les noeuds selon l'exemple ci-dessus. –

+0

Votre code remplace uniquement les noeuds racines et non les noeuds enfants sous le premier. Remplacer pour chaque oNode dans .Nodes par pour chaque oNode dans .AllNodes fonctionne. :-) –