2011-01-19 12 views
5

Quindi ho questa macro che fondamentalmente analizza ogni diapositiva in PowerPoint e imposta la lingua specificata. Funziona alla grande. Come sempre, salta i contenitori che non sono caselle di testo. Mi piacerebbe che applicasse la lingua su tabelle, smartart, grafici ecc. Fondamentalmente tutto ciò che può contenere testo.PowerPoint 2007 - Imposta la lingua su tabelle, grafici ecc. Che contiene il testo

È possibile? Questo è il codice corrente:

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 

risposta

7

Sì, non è tutto ciò che intuitivo in PowerPoint, ma si può fare. Fondamentalmente, ci sono 3 tipi principali di forme (semplici, raggruppate e tabelle). Questo codice li controlla:

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 
     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 
+0

Funziona molto bene! Ma non sembra controllare SmartArt. È possibile? Microsoft avrebbe dovuto includere la registrazione Macro nella versione 2007, così ho potuto registrare cliccando su un oggetto SmartArt, capendo quale tipo fosse effettivamente. –

+0

Controlla SmartArt al mio fianco, ma ho provato su PowerPoint 2010. Anche nel 2007, sebbene SmartArt sia considerato "oShape.GroupItems". Se provi a provarlo su un altro mazzo con SmartArt ottieni gli stessi risultati? –

+0

@Kenny Bones: sei riuscito a provare questo con un mazzo diverso? –

0

Ho avuto lo stesso problema quando si fa macro per cambiare la lingua in tutte le forme. Per quanto ho appreso, in PPT2007 non è possibile impostare la lingua sugli oggetti come Grafici e SmartArt, in modo programmatico. Non c'è accesso per impostare languageID in VBA su questi oggetti. Tuttavia, cambiando la lingua facendo clic sull'oggetto SmartArt o sull'oggetto Chart funziona.

Per gli altri oggetti:

  • elementi raggruppati - ho dovuto attraversare programatically (come in esempio nel post di Otaku) attraverso tutti gli oggetti in un gruppo per impostare una lingua
  • tavolo - ho attraversato tutta le cellule.
0

Anche se un po 'di tempo è passato ... è venuto qui da https://superuser.com/questions/432366/how-do-i-change-the-language-of-all-powerpoint-slides-at-once. Dato che preferisco lavorare con python, una versione python che usa il pacchetto win32com sarebbe:

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() 
Problemi correlati