Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Smart Art 1

Status
Not open for further replies.
Sorry - I don't have the time (or inclination) to wade through over 3.5k lines of code to try and figure out where you are struggling.

Providing code is greart, but to start with we just need to see the code where you are having the problem, or where you need guidance.

But right now, I still donm't understand exactly what you are trying to do.

You may think that " wanted to copy text from a sheet automatically into a list style smart art" explains everything, but it isn't clear at all. At least not to me.
 
Why not just click on the record macro button and then do what you would want to do manually with the smart art and see what code gets generated.

It will be something like
Code:
call activesheet.shapes.addsmartart(application.smartart.layouts(...)).select
...
 
From the docs link provided by strongm....

You can't do what you want to do.

You can't do very much at all to manipulate SmartArt via VBA. Which is too bad really.
 
A macro recorder can help a little when you create a smart art, esp. to get layout string reference. In the next step one can experiment a bit with already created smart art, get reference to it (it's a shape), in a break mode examine model in Locals window. Finally, object browser shows properties and methods.
Smart art does not accept VBA mistakes, excel closes without warning, it's a good habit to save file before testing the code.

Here's my first code with SmartArt after few tests, for active sheet:
Code:
Sub test()
Dim shpSmartArt As Shape
Dim strSAname As String
strSAname = "mySmartArt"
' create sample SmartArt
Set shpSmartArt = CreateSmartArt(strSAname)
' move 'child node 3' up
shpSmartArt.SmartArt.Nodes(1).Nodes(3).ReorderUp
' change 'child node 3' text, now second cild node
shpSmartArt.SmartArt.Nodes(1).Nodes(2).TextFrame2.TextRange = "changed text"
End Sub

Public Function CreateSmartArt(sName As String) As Shape
Dim shpSmartArt As Shape
' create sample SmartArt
Set shpSmartArt = ActiveSheet.Shapes.AddSmartArt(Application.SmartArtLayouts("urn:microsoft.com/office/officeart/2008/layout/LinedList"))
With shpSmartArt
    .Name = sName
    With .SmartArt
        'remove all except root default child nodes
        For i = .AllNodes.Count To 2 Step -1
            .AllNodes.Item(i).Delete
        Next i
        With .Nodes(1)
            .TextFrame2.TextRange = "root node"
            For i = 1 To 5
                With .Nodes.Add
                    .TextFrame2.TextRange = "child node " & i
                    .Demote
                End With
            Next i
        End With
    End With
End With
Set CreateSmartArt = shpSmartArt
End Function

combo
 
COMBO
Thanks for the really useful post. I had nothing on SmartArt manipulation.
C57
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top