Home | VBA Section | General Section | Downloads | Licensing | Privacy Policy | OfficeTips RSS Feed

SmartArt object

PPT 2010 finally adds SmartArt support in the object model and it is quite extensive. In PPT 2007, the smartart information could only be read by treating the shape as a group or breaking it apart (See: Extract text from SmartArt).



'Enumerate all the layouts available on the system
For I = 1 To Application.SmartArtLayouts.Count
     Debug.Print Application.SmartArtLayouts(I).Category
     Debug.Print Application.SmartArtLayouts(I).Id
     Debug.Print Application.SmartArtLayouts(I).Name
     Debug.Print Application.SmartArtLayouts(I).Description
Next


'To create a smartart shape, you need to pass a reference to the type of smartart layout you wish to create
Dim oSALayout As SmartArtLayout
Set oSALayout = Application.SmartArtLayouts(1)
'Get a reference to the 1st smartart layout

'Create a smartart shape
Set oShp = ActivePresentation.Slides(1).Shapes.AddSmartArt(oSALayout)

'Add text to the Smartart
For I = 1 To oShp.SmartArt.AllNodes.Count
  oShp.SmartArt.AllNodes(I).TextFrame2.TextRange.Text = "Sample " & I
Next

'Read the text back
With oShp
     If .Type = msoSmartArt Then
          For I = 1 To .SmartArt.AllNodes.Count
               Debug.Print .SmartArt.AllNodes(I).TextFrame2.TextRange.Text
          Next
     End If
End With

 

 


Copyright © 1999-2009 Shyam Pillai. All rights reserved.