• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 394
  • Last Modified:

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


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.
Thomas Woehlke
Thomas Woehlke
  • 3
  • 2
1 Solution
Scott HelmersVisio Consultant, Trainer, Author, and DeveloperCommented:
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.
Thomas WoehlkeAuthor Commented:
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.
Scott HelmersVisio Consultant, Trainer, Author, and DeveloperCommented:
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

Thomas WoehlkeAuthor Commented:
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.
Scott HelmersVisio Consultant, Trainer, Author, and DeveloperCommented:
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?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now