Author Topic: VBA for swapping two connected shapes  (Read 368 times)

0 Members and 1 Guest are viewing this topic.

Visisthebest

  • Jr. Member
  • **
  • Posts: 26
VBA for swapping two connected shapes
« on: July 30, 2018, 11:45:51 AM »
Hi All,

Just found this forum, how great this resource exists!

I am new to VBA and Visio, have been exposed much more to Javascript (all the good and the bad of JS).

We have a huge flowchart diagram where a lot of shapes are connected from left to right, each one with an incoming connection and an outgoing connection.

These shapes have a time in seconds or even milliseconds associated with them (they are events). They should be chronological but people people can make the mistake of sometimes putting an event out of order, most often meaning that one event connected to the other (directly) needs to be swapped to repair the chronological order.

What is important to know and to consider before starting out to write some VBA code to swap two events connected next to each other? The other connections these events have with other shapes should also be connected to the swapped shape. The shapes have identical sizes (rectangles). All the data on these shapes needs to move along with the swap.

Your ideas for how to start out making some VBA for this are greatly appreciated.

Warm regards,

Max Larsen

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3256
  • Ideas Visio-lized into solutions
Re: VBA for swapping two connected shapes
« Reply #1 on: July 30, 2018, 08:00:43 PM »
Take a look at Paul Herber's Super Utilities.   

Wapperdude
Visio 2007 Std

Visisthebest

  • Jr. Member
  • **
  • Posts: 26
Re: VBA for swapping two connected shapes
« Reply #2 on: July 31, 2018, 06:48:22 AM »
Wapperdude thank you great functionalities in that tool kit, but it doesn’t do shape swapping and reconnecting unfortunately.

metuemre

  • Full Member
  • ***
  • Posts: 136
Re: VBA for swapping two connected shapes
« Reply #3 on: July 31, 2018, 08:08:54 AM »
It will be helpful if you can provide a sample visio file. What you want can be done with VBA

Paul Herber

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2639
    • Paul Herber's website
Re: VBA for swapping two connected shapes
« Reply #4 on: July 31, 2018, 08:34:46 AM »
Take a look at Paul Herber's Super Utilities.   

Wapperdude
thanks dude,. I'm sorry but my utilities can't do that.
Electronic and Electrical engineering, business and software stencils and applications for Visio -

http://www.paulherber.co.uk/

Visisthebest

  • Jr. Member
  • **
  • Posts: 26
Re: VBA for swapping two connected shapes
« Reply #5 on: July 31, 2018, 09:02:01 AM »
Great tools Paul will probably buy them!

I will make a sample file, but it is virtually identical to a cross-functional flowchart but with fine-grained times on the columns. (for instance, from electronic aviation system logs and other data sources for doing accident investigation, challenge is that the examples I have are confidential need to make an example without real data)

The swap is for horizontally-connected shapes that need to be swapped.

Thanks!

Max

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3256
  • Ideas Visio-lized into solutions
Re: VBA for swapping two connected shapes
« Reply #6 on: July 31, 2018, 09:21:14 AM »
As I have V2007, haven't explored this myself.  But, with V2013, there is a change shape feature that might meet your needs.  https://blogs.msdn.microsoft.com/officedevdocs/2012/08/23/change-shapes-in-visio-2013/

HTH
Wapperdude
Visio 2007 Std

Visisthebest

  • Jr. Member
  • **
  • Posts: 26
Re: VBA for swapping two connected shapes
« Reply #7 on: July 31, 2018, 07:34:29 PM »
Yes Wapperdude thank you but I am looking for almost the inverse of that functionality, all the shape data and properties should move with the swap rather than stay put. I’ll experiment with this in the coming weeks and share my code when it works, I’ll write it generically so it works on cross-functional flowchart type diagrams and similar.

AJD

  • Jr. Member
  • **
  • Posts: 21
Re: VBA for swapping two connected shapes
« Reply #8 on: August 05, 2018, 03:24:22 PM »
Spit-balling here, don't have the opportunity to test this out any time soon.

You imply that the connectors are directional, so you could perform a check to see if the <timevalue> of the object on the left (the incoming connector) is less than the <timevalue> of the current object. Similar checks for the object on the right. This is a simple pair of YES/NO that could be displayed graphically (e.g. change the colour of the shapes etc).

To make life easier, a custom shape (I assume you are using those anyway) that constrains the types and directions of connectors (perhaps even custom connectors). If using standard shapes and connectors, you can determine visual direction by identifying which end of the connector is connected to which shape and then identifying which end has the arrow head. But, constraining the shapes makes these checks easier.

This is based on some work I did a few years ago (hence lack of fine detail here) to traverse a connected graph which used semi-standard connectors that the users could swap and modify in the UI.


Visisthebest

  • Jr. Member
  • **
  • Posts: 26
Re: VBA for swapping two connected shapes
« Reply #9 on: August 07, 2018, 07:06:54 AM »
Thank you for this very useful to think about these options!

pavane

  • Newbie
  • *
  • Posts: 8
Re: VBA for swapping two connected shapes
« Reply #10 on: September 09, 2018, 02:10:29 AM »
Can you not just swap the contents?

Visisthebest

  • Jr. Member
  • **
  • Posts: 26
Re: VBA for swapping two connected shapes
« Reply #11 on: September 16, 2018, 07:12:27 AM »
Can you not just swap the contents?

Panave yes that is a possibility too, do you expect that to be faster as well? What is a good way to do this in VBA so it is truly one transaction, if any part of it doesn’t execute properly (which would corrupt the data) the entire transaction is (automatically for the user) reversed and the user gets a prompt informing him/her the swap hasn’t gone through?

Paul Herber

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2639
    • Paul Herber's website
Re: VBA for swapping two connected shapes
« Reply #12 on: September 16, 2018, 09:33:41 AM »
First, set the Undo scope, so that if it goes wrong then all you have to do apply the undo and it will happen.
Next, it will depend on what shape properties you need to swap. Are the shapes of the same type? Is it just text to be swapped?
Electronic and Electrical engineering, business and software stencils and applications for Visio -

http://www.paulherber.co.uk/

Visisthebest

  • Jr. Member
  • **
  • Posts: 26
Re: VBA for swapping two connected shapes
« Reply #13 on: September 16, 2018, 06:22:22 PM »
Thank you Paul, same shapes yes, both text and shape data need to be swapped.

Visisthebest

  • Jr. Member
  • **
  • Posts: 26
Re: VBA for swapping two connected shapes
« Reply #14 on: September 16, 2018, 06:25:29 PM »
Oh yes I forget there may be more causal links than just on the horizontal line, so some connections may have to be reconnected from the one shape to the other and vice versa if just the properties of the shape are moved over.
« Last Edit: September 16, 2018, 06:28:53 PM by Visisthebest »