vbavstoms-officeoffice-2010

How can I set the picture associated with a node in a SmartArt graphic?


SmartArt graphics can have pictures associated with the "nodes" (although this is only used by certain SmartArt templates). I know how to set the text of a node via VBA/VSTO automation, but I can't figure out how to set the picture.

Can it be done?


Solution

  • Try something like this - if you've done any work in VBA with smartart this should make sense.

    Dim oSALayout As SmartArtLayout
    Dim QNode As SmartArtNode
    Dim oShp As Shape
    
    Set oSALayout = Application.SmartArtLayouts(91) 'reference to organization chart
    Set oShp = Chart.Shapes.AddSmartArt(oSALayout, ileft, 2, iWidth, iHeight)    
    Set QNode = oShp.SmartArt.AllNodes.Add
    
    ...
    
    ' note that there may be more than one shape associated with each node, I found that those org chart/smart art layouts with a specific "picture box" typically use Shapes.Item(2) 
    
    With QNode.Shapes.Item(1).Fill
        .Visible = msoTrue
        .UserPicture "c:\somepath\picture.jpg"
        .TextureTile = msoFalse
    End With
    

    hope that makes sense!