Visio: set Org-Chart Layout per VBA

Hi Experts,
I have written some script to build up an org chart in Visio (2010 and 2013) using vbscript.
Unfortunately the macro recorder does not record everything you do within the GUI :-(

My orgchart output is almost fine, but in some cases I need to apply a different layout than the default one.
What I want is to set layout properties to my selection in VBA that are equivalent to when I select:
Ribbon: Orgchart
Group: Layout
Button: one of those provided on "Side by Side" selection.

How would I do that in VBA?


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott HelmersVisio Consultant, Trainer, Author, and DeveloperCommented:
The macro recorder doesn't record many UI functions related to org charts because a lot of what happens in org charts is handled by the org chart add-in; it's actually supplemental code that runs beside, but not as part of, the Visio engine. The org chart add-in is also responsible for creating the Org Chart tab on which you found the buttons you referred to.

The good news is that there is some documentation on automating org chart functions. Please see this article for a specific example. At the end of the article you'll find a reference to a list of parameters for automating org chart functions.

NOTE: just before submitting my response I tried following the link to the list of parameters. Unfortunately, the link is broken. As an alternative for the moment, download the code cited in my article because I retained but commented out the parameters I didn't need for that article.
Lupo09Author Commented:

I found the Parameter list here. I thik, this is the llist you meant.
Unfortunately I don't find any method to modify the layout among these parameters...

I see that these buttons and that particular org Chart tab is created by the add-in, but anyway, i was hoping to find vba functions to modify and optimize the layout. I thought a function that is triggered by click on a button also could be invoked within a script in VBA?

I found the layout method, that does some optimizing on common shapes, I need this for org Charts...

Any more thoughts on this?


Chris RothCommented:
Hi Kai,

Maybe more work than you want to undertake, but you can actually analyze the connectivity of the Visio drawing. This article talks about it (download the Visio file and look at the VBA):

Also, for Visio 2010 and newer, there is a shp.ConnectedShapes method (see:

This method lets you deal only with the boxes, as opposed to having to look at the connectors, figure out what they're glued to, then figure out what they're glued to on the other end, then find the boxes on the other end, yada yada yada, phew!

For an orgchart, you would start with a position shape (call it a "node"), then get the outgoing connected shapes from that node. Continue on for each connected shape, building a tree structure.

Then you can use shp.BoundingBox to get the size of each shape, and do your own geometry/math/layout-code.

Hope this points you in the right direction!
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

Scott HelmersVisio Consultant, Trainer, Author, and DeveloperCommented:
Yes, Kai, the list you found is the one I had in mind. Unfortunately, the org chart add-in does not expose every function and the layout options are excluded. About the only other option I can think of to invoke the layout functions is to simulate keystrokes. For example,
   Alt+O, S, DownArrow, DownArrow, Enter
selects Double-Side under Side by Side. It's not particularly elegant, but you should be able to do this via SendKeys().

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Lupo09Author Commented:

thasnks for clarifying how things are handlet within Visio and the Add-in.

Unfortunateliy there doesn't seem  to be a solution for what I want. Sending keystrokes doesn't seem to be save enough as the users might have different localized versions of vision installed on their machines...

The idea was to automaticcaly fit the org chart to the page and then export it to PDF.

Now I'll leave it with creating the org chart and let the user do the final optimizing.

Maybe you have an idea for how to accomplish a "fit to page" task...


Scott HelmersVisio Consultant, Trainer, Author, and DeveloperCommented:

In case you're still dealing with this issue, I learned something from Visio MVP John Goldsmith last month that should help.

John pointed out a trace feature that displays the commands that are used by the org chart add-on. You can then use those commands in your VBA code, eliminating the need for the clumsy use of SendKeys().

To activate the trace, type this in the Immediate window (or use this command in your VBA code):
    Application.TraceFlags = visTraceAddonInvokes
To turn off the trace:
   Application.TraceFlags = False

With trace on, click any button on the Org Chart tab to see its command. For example, this is the command that results from clicking one of the Layout buttons (the specific "cmd=xxx" entry will change based on which layout button your click):
   >invokeAO: name='Organization Chart' nameU='OrgC11' args='/cmd=gallery_horiz6'
and this is the command from clicking the + sign next to the Spacing button in the Arrange group:
   >invokeAO: name='Organization Chart' nameU='OrgC11' args='/cmd=movefurther'
This one is the result of changing to a different style:
   >invokeAO: name='Organization Chart' nameU='OrgC11' args='/cmd=style03'

This VBA code applies a layout and increases spacing three times:
        Visio.Application.Addons("OrgC11").Run ("/cmd=gallery_horiz1")      ' apply desired layout
        Visio.Application.Addons("OrgC11").Run ("/cmd=movefurther")         ' increase spacing
        Visio.Application.Addons("OrgC11").Run ("/cmd=movefurther")
        Visio.Application.Addons("OrgC11").Run ("/cmd=movefurther")

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Visio

From novice to tech pro — start learning today.