Change SmartArt Layout in VBA

OllieHosking

New Member
Joined
Oct 1, 2021
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I currently have a VBA macro in excel that is creating and populating a SmartArt Organisation Hierarchy, I want to have another macro afterwards that then changes the layout to a different one.

In my mind this is possible, but I am a shambles when it comes to VBA!

Any help will do.

Thank you,
Oliver
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
You can assign a layout by index number (ie. the first layout is 1, the second is 2, and so on). Therefore, to assign a layout, let's say the third layout, try . . .

VBA Code:
Worksheets("Sheet1").Shapes("Diagram 1").SmartArt.Layout = application.SmartArtLayouts(3)

Change the name of the worksheet and shape accordingly.

Hope this helps!
 
Upvote 0
Hello,

I am currently using this line in the macro, but I would like it to create that layout and then change it to another one, is that possible?

Thanks,
Oliver
 
Upvote 0
The following code does the following...
  1. creates a smart art diagram on the active sheet
  2. assigns the first layout, Layout 1
  3. positions the top left corner at cell B2
  4. sets the width and height according to the size of B2:G0
VBA Code:
    Dim shp As Shape
    Set shp = ActiveSheet.Shapes.AddSmartArt( _
        Layout:=Application.SmartArtLayouts(1), _
        Left:=Range("B2").Left, _
        Top:=Range("B2").Top, _
        Width:=Range("B2:G10").Width, _
        Height:=Range("B2:G10").Height)

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,315
Members
452,634
Latest member
cpostell

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top