Solved

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
5
73 Views
Last Modified: 2016-10-26
Hello,

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.
0
Comment
Question by:Thomas Woehlke
  • 3
  • 2
5 Comments
 
LVL 30

Expert Comment

by:Scott Helmers
Comment Utility
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.
0
 

Author Comment

by:Thomas Woehlke
Comment Utility
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.

https://support.microsoft.com/en-us/kb/2518512

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.
0
 
LVL 30

Accepted Solution

by:
Scott Helmers earned 500 total points
Comment Utility
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

0
 

Author Comment

by:Thomas Woehlke
Comment Utility
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.
0
 
LVL 30

Expert Comment

by:Scott Helmers
Comment Utility
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
shp.delete
<add control here>

Open in new window

Does that make sense?
1

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The code described here does no longer work. Please see replacement Article: http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/A_3887-Getting-your-EE-Ranking-statistics-in-Excel-The-Next-Generation.html (http…
Modern/Metro styled message box and input box that directly can replace MsgBox() and InputBox()in Microsoft Access 2013 and later. Also included is a preconfigured error box to be used in error handling.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now