Automating multiple groups of objects with VBA

Started by Archangelos, August 04, 2016, 06:41:04 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Archangelos

Hi guys,

in the attached picture you can see a schematic I have made in Visio 2007. There are multiple groups of objects that are copied multiple times.

For example, the part of the schematic that is in blue colour is copied a few times.

Until now, I copy it to clipboard, paste it as many times as I need and then I have to edit the labels manually. Is it possible to have it done automatically? Can VBA help me automate the process?


Nikolay

I don't think it makes sense to automate that process..
Doesn't copy/paste/adopt look fine - what exactly do you want to change here?
How the tool is supposed to know what labels should it put there for the pasted fragment?

Archangelos

Quote from: Yacine on August 04, 2016, 08:39:33 PM
You could use VBA, but for this case linking to data seems to be more appropriate.
Check this:
https://support.office.com/en-us/article/Link-data-to-diagrams-I-Getting-started-6b637f40-6231-4822-a81e-65d622fb8c13
https://blogs.office.com/2013/04/25/data-linked-diagrams-linking-data-from-an-external-data-source/
Thanks buddy. I will study them.
Yesterday I placed an order on amazon for the book "VBA for dummies". I hope it will help me. I have done a few funny things in excel but I have never used VBA in visio.



Quote from: Nikolay on August 04, 2016, 09:06:36 PM
Doesn't copy/paste/adopt look fine - what exactly do you want to change here?
Well, copy/paste helps in order tp get the group of shapes as many times as I need. However, all the labels will have the same value.
For example, in the blue fragment the top label says "ID 0". If I copy it five times then in all copies the label will say "ID 0". I will have to correct the labels manually. This is time consuming and counter productive.


Quote from: Nikolay on August 04, 2016, 09:06:36 PMHow the tool is supposed to know what labels should it put there for the pasted fragment?
I suppose there are two ways.
1. Embed the labels texts into the code (I can live with that).
2. I should have the label texts in a .txt file (tab separated) and have the code assign the label texts to each copy.

Yacine

Quote from: Archangelos on August 05, 2016, 05:56:47 PM
I will study them.
Yesterday I placed an order on amazon for the book "VBA for dummies". I hope it will help me. I have done a few funny things in excel but I have never used VBA in visio.

You misunderstood me. You don't need VBA for this application.
Add the custom properties you need to the shapes.
Set up an excel sheet with data.
Dupplicate the shapes in the drawing as needed, then link the rows of the excel table to the shapes.
This is a built-in feature of Visio.
Yacine

Nikolay

#5
Quote from: Archangelos on August 05, 2016, 05:56:47 PM
Quote from: Nikolay on August 04, 2016, 09:06:36 PMHow the tool is supposed to know what labels should it put there for the pasted fragment?
I suppose there are two ways.
1. Embed the labels texts into the code (I can live with that).
2. I should have the label texts in a .txt file (tab separated) and have the code assign the label texts to each copy.

But wouldn't this require you to do double-work?
Means, first, create shapes/drawing, and then change the code/text/excel file, and then apply that file?

Automation only makes sense when there are repeated operations that can be automated. In you case, it looks like there is no repetition. You create shape and specify their pin connections, are you not? Or there is some logic how the pins are named, and you want to take advantage of that?

If not, then I fail to see how that can be automated.. If you specify the same in the text/excel file, this will just make your life harder, you'll have to maintain two files, but it will not save the number of keyboard presses - you'll need to enter the same data, but in that (other) file, probably without context.?

Archangelos

Firstly, thanks for your help.

Quote from: Yacine on August 07, 2016, 11:20:30 AMYou misunderstood me. You don't need VBA for this application.
Add the custom properties you need to the shapes.
Set up an excel sheet with data.
Dupplicate the shapes in the drawing as needed, then link the rows of the excel table to the shapes.
This is a built-in feature of Visio.
I suppose it is possible to change the label text through the custom properties. Is it also possible to change font colur, background colour, size etc?



Quote from: Nikolay on August 07, 2016, 12:34:40 PMOr there is some logic how the pins are named, and you want to take advantage of that?
generally, there is not such a logic. It is most likely that the pins are named in a random way.

Quote from: Nikolay on August 07, 2016, 12:34:40 PMIf not, then I fail to see how that can be automated..
I think it is me who failed to understand. I am totally inexperienced in Visio with VBA.

Archangelos

Quote from: Yacine on August 04, 2016, 08:39:33 PM
You could use VBA, but for this case linking to data seems to be more appropriate.
Check this:
https://support.office.com/en-us/article/Link-data-to-diagrams-I-Getting-started-6b637f40-6231-4822-a81e-65d622fb8c13
https://blogs.office.com/2013/04/25/data-linked-diagrams-linking-data-from-an-external-data-source/
The first link is not available anymore.

The second is still up and running but it has a dead link. A file that had been made in order to be used by anyone who needs help is not available.

Microsoft Help stinks. Enjoy.