MS Visio Question about changing shape IDs in code or setting a value for them when they are initially dropped into drawing.

Posted on 2016-10-20
Last Modified: 2016-10-26

I'm currently creating a controls enabled Visio drawing. The drawing is a schematic, and on the schematic there are options which can either be present or not present using check boxes (turning layers on and off), and there are options that specify a part number, or set a "Label" based on which radio button is selected. I have the macros code working well enough for the two features I just described.

The problem I am now facing is that I'm hitting the 1024 shape ID limit for adding new controls. Since I do not know how the schematic is going to look while I'm creating this document, I cannot just add all the controls needed and then add the shapes accordingly. I will also need co-workers to be able to edit the drawing and add controls without needing too much knowledge of how the macros works.

From what I've read so far the shape ID is read only so changing that in a macros to allow me to add more activeX controls to the document will not work. If this is not true please assist with this option.

Is there a way to make visio drop in non-activeX control shapes with a starting shape ID of 1024+ and then when I need to add an activeX control add it at 1+?

I guess if push comes to shove, when I create a new page I can populate a page with 150 of each control I use which will probably be enough for my purposes. I'd rather not take this route because it may limit the document design down the road.
Question by:Thomas Woehlke
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 30

Expert Comment

by:Scott Helmers
ID: 41854196
What is happening that leads you to believe you're running into a shape ID limit? I ask for two main reasons: Shape IDs are assigned per page so the contents of one page don't affect another page; it's possible to have more than 1024 objects per page. For example, I just wrote a macro that added 1050 shapes to a page (1050 is a totally arbitrary number but is greater than 1024). The last shape on the page is Sheet.1050.

Can you tell me more about what specific problem you're encountering?

BTW, you are correct that you cannot change a shape's ID; you can change its name but not its ID.

Author Comment

by:Thomas Woehlke
ID: 41854440
Hey Scott,

I really liked your Visio Power Users Modules on the Microsoft academy website.

Sorry I did not include the error, I should have though to do that. the error is 1441.

It's not that I can't add a new shape, I can't add a new activeX control shape. The workarounds listed in the link I sent do not work well with the project i'm working on because it requires the user to have the foresight to know how many controls they need prior to working on the schematic.
LVL 30

Accepted Solution

Scott Helmers earned 500 total points
ID: 41854589
I'm glad you enjoyed the Microsoft Virtual Academy tutorials.

Thanks for the additional explanation -- now I understand what's up. I haven't played a lot with controls and wasn't aware that they couldn't have IDs > 1024.

One of the suggestions in the article you cited sounds like it could work:
Put some placeholder shapes on the page first. These placeholders can be hidden or positioned off the page. When you want to insert a control, delete a placeholder, and replace it with the control. The new control will take the ShapeID for the placeholder that was deleted. And, this ShapeID will be less than 1024.

Let's say the maximum number of controls you could need to add is 50. Ensure that each page is blank then place 50 invisible shapes on each page; they will be Sheet.1 through Sheet.50. Then, the first time you need to place a control on the page, delete Sheet.1 and add your control. For the next one use Sheet.2, etc.

This is simple-minded code but will do the job for creating tiny invisible shapes:
Option Explicit

Sub PlaceInvisibleShapes()

    Dim i       As Integer
    Dim shp     As Visio.Shape

    For i = 1 To 50
        Set shp = ActivePage.DrawRectangle(0, 0, 0.001, 0.001)  ' draw a very tiny shape
        shp.Cells("Geometry1.NoShow").Formula = True            ' make it invisible
    Next i

End Sub

Open in new window


Author Comment

by:Thomas Woehlke
ID: 41860216
Hey Scott,

Thanks for the suggestion. It is a valid approach to the problem. One quick note though. If there is a macro running that is holding the the shapes on the page and that ID is above 1024 then you still will not be able to add a control to the page.

On The current page that is running into the OLE activeX limit, if all the shapes in the page are cut and pasted into another page and then more controls are added the error will still occur.

I ran a macro to track the number of shapes, by setting a visio.shapes variable to shapes on the active page.

-Before moving the shapes over to another page there is a shape count of 256 shapes, with a high shape ID of 1587
-After moving the shapes over to another page there is a shape count of 19 shapes, with a high shape ID of 255

However once the shapes are relocated to another page and the macros is stopped Visio allowed me to put in more controls.
LVL 30

Expert Comment

by:Scott Helmers
ID: 41860317
Just to be sure we're talking about the same thing:
The macro I provided simply creates 50 shapes. It isn't running in the background or holding shapes on a page. My concept is that you would run this macro once on each page in a new diagram -- one that doesn't have any shapes on any page. At this point the diagram is ready for you to add the shapes you need.

When you copy your existing shapes to the pages of the diagram, the quantity of those shapes and their shape IDs are essentially irrelevant because they were preceded on the page by 50 hidden shapes numbered 1 through 50. Immediately prior to adding a new control, you simply do something like this:
set shp=ActivePage.Shapes(n)   ' n is a number from 1 to 50
<add control here>

Open in new window

Does that make sense?

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The code described here does no longer work. Please see replacement Article: (http…
Being an active EE Expert means to get a lot of (E)EMail, as you certainly know. If you are using Outlook, I'll show you how to minimize your inbox contents without losing anything – even improve the experience by changing the Subject line to facili…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question