Author Topic: Ribbon Buttons for Multiple Connector Styles  (Read 419 times)

0 Members and 1 Guest are viewing this topic.


  • Jr. Member
  • **
  • Posts: 12
Ribbon Buttons for Multiple Connector Styles
« on: April 17, 2018, 11:49:04 AM »
Hey all!

I want to add a few buttons to the Ribbon that allow the user to create dynamic connectors with predetermined line styles.

Ideally, I'd have one button per specific line style that I need. The buttons would pass the line style info to a macro or sub-routine that acts exactly as if the user pressed the Connector Tool on the Ribbon:
  • click & hold in one spot to designate the start of the connector, drag to another spot, and release the mouse button to designate the end of the connector
    (alternatively, I'd settle for first click / second click to designate the start / end)
  • Dynamic Connector is created with the predetermined line style
  • the tool keeps running until the user either selects a different tool or presses ESC

Is there a way to use VBA to do this?
Or maybe there's another better way to accomplish this task?

I already know how to customize the Ribbon using VBA, but I need some help figuring out how to mimic the Dynamic Connector Tool behavior.

Running Visio Standard 2016 with Windows 7 Enterprise on a 64-bit machine.

Thanks in advance for your help!

P.S. This is essentially a cross-post of someone else's topic from late February that got no replies. I am re-wording and re-posting the topic here, as I think it is more relevant to Programming & Code (and might actually get a few replies :D).


  • Hero Member
  • *****
  • Posts: 2515
Re: Ribbon Buttons for Multiple Connector Styles
« Reply #1 on: April 18, 2018, 09:13:30 AM »
Challenging indeed.

I could think of the following scenario.

Each custom connector button implements a method that executes the code to draw a connector.
Ideally a direct call would be made (if known), but the direct call could be substituted by addressing the connector button as shown here:
The custom button would then start an event listener for the shape added event. It would set a variable at document level so you know which drawing mode is selected.
In the document_shape_added event handler you would check for the drawing mode variable and depending on its value reformat the connector to your need.

Eager to see what you come up with.
« Last Edit: April 18, 2018, 09:19:18 AM by Yacine »


  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3341
  • Ideas Visio-lized into solutions
Re: Ribbon Buttons for Multiple Connector Styles
« Reply #2 on: April 18, 2018, 09:51:58 AM »
First, I hate using events.  Invariably quite frustrating...for me. 

Nonetheless, an embellishment to Yacine's suggestion...
1)  each GUI button triggers a separate macro that handles the various attributes.  Attribute setting is done at the end of the macro, after a connector has been placed.  The code takes advantage of the fact that the connector in question is, by default, selected.

2) I think you might need mouse button up/down events to signal start of new connector and finish of connector.

3) the macro needs a loop so it will start a new connector after each completed connector.

Just some thoughts...


« Last Edit: April 18, 2018, 11:09:22 AM by wapperdude »
Visio 2019 Pro


  • Full Member
  • ***
  • Posts: 159
Re: Ribbon Buttons for Multiple Connector Styles
« Reply #3 on: April 19, 2018, 06:49:29 AM »
I think Yacine's suggestion is easier to implement. I attached a simple example that may be helpful.



  • Hero Member
  • *****
  • Posts: 2515
Re: Ribbon Buttons for Multiple Connector Styles
« Reply #4 on: April 20, 2018, 12:33:44 AM »
Veeery nice ;)


  • Jr. Member
  • **
  • Posts: 12
Re: Ribbon Buttons for Multiple Connector Styles
« Reply #5 on: April 20, 2018, 11:03:09 AM »
Thank you guys so much for your responses!
(can't believe how responsive you all are :D :D)

I read up on the references that Yacine and Wapper provided to get some technical background. I have been working with the docs posted by metuemre to finalize my solution, which I am hoping to post today.

(it's been taking a bit longer than I thought it would, but I will be implementing a dynamic splitButton control that updates it's label depending on the currently active line style - might not be exciting for you guys but I'm pretty stoked!;D)


  • Jr. Member
  • **
  • Posts: 12
Re: Ribbon Buttons for Multiple Connector Styles
« Reply #6 on: April 20, 2018, 12:15:43 PM »
Actually, I totally forgot I did have a few questions regarding the XML in metuemre's docs...
  • Each line starts with mso: after the bracket (see full XML string below). What exactly does that do?
    (don't get me wrong, my experience with XML is very limited but all the code examples I have seen just start with the tag name like ribbon, tab, group, button, etc.)
  • On a different document where I am implementing Ribbon customizations, the XML string starts with snippet below as the first line. However, this snippet is not on metuemre's XML. Any idea what this snippet does and how necessary it is?
        <?xml version="1.0" encoding="UTF-8"?>
  • The snippet below is line 3 of metuemre's XML. Does this just hide the Quick Access Toolbar (if the user has previously created one)?
  • Is there a way to nest a code block inside of a list using BBC on this forum (tried a few times without success on this post ha)?

The full XML string produced by metuemre's doc:
Code: [Select]
<mso:customUI onLoad="OnRibbonLoad" xmlns:mso="">
      <mso:tab id="customTab" label="CUSTOM TAB">
        <mso:group id="group1" label="Line Patterns" autoScale="true">
            <mso:splitButton id="customSplit">
             <mso:button id="Objects" imageMso="LineStyle2" label="Dash Type" />
                <mso:menu id="customMenu">
                   <mso:button id="Solid" onAction="OnAction" label="Solid" />
                   <mso:button id="Dash" onAction="OnAction"  label="Dash" />
                   <mso:button id="Dot" onAction="OnAction"   label="Dot" />
                   <mso:button id="DashDot" onAction="OnAction"  label="Dash Dot" />
                   <mso:button id="DashDotDot" onAction="OnAction"  label="Dash Dot Dot" />
                   <mso:button id="DashDashDot" onAction="OnAction"  label="Dash Dash Dot" />
                   <mso:button id="LongDashShortDash" onAction="OnAction"  label="Long Dash Short Dash" />

snippet  snippet  snippet  snippet       ....... just trying to see how many more times i can say "snippet" in one post lol  :P