Loop finds shape that does not exist

Started by chrisoft, January 18, 2017, 10:14:12 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

chrisoft

Dear visGuy,

I am facing to an issue that seems strange when I loop over all shapes in activepage.
The loop finds a shape that does not exist in the page. Then this "ghost" shape raises an error up.
I have tried to find it by "search" function in Visio but no results.
I have also check the layer and all are set unlocked and visible.

Here is the code below


Sub test()

    Dim shp As Shape
   
    For Each shp In ActivePage.shapes
        Debug.print shp.id

        'here the error raises up because the shape is not in the page whereas the loop find it.
        If shp .Type = 2 Then
         
        End if

    Next
End Sub


Does someone know about this bug ?

Paul Herber

A Type 2 shape is a grouped shape. What are you doing with your code?
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

chrisoft

Dear Paul,

Thanks for your reply.

The code posted is a sample of a big function.
I loop over all shapes and if shape is a group then continue code within the test function. (usual code I would say)

I notice the "ghost" shape found by the loop is named "Sheet.201". mostly it's a name automatically given by visio when it's a group.
But I do not have any shape called Sheet.201 in my visio (even in others pages).

I could catch the error number and manage it as an alternative solution.
I have a lot of functions that are looping over all shapes after this one, it means to implement the error handling in each functions  :-\
Not sure this is the right solution. I have never seen such bug since I have been working with Visio.

Paul Herber

Is the shape visible in the Drawing Explorer window?
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

chrisoft

Dear Paul,

Of course not, otherwise it would not be funny  :P

But the most funny is that I have deleted all shapes in the drawing and the bug is still there. I have a blank page with no layer + I have deleted the temp stencils.

For your easy ref I have attached the doc  ;)
you can lauch the sub in the module and see.

Thanks for your help

Paul Herber

Drawing Explorer window != visible drawing area.
menu Developer -> (Show/Hide section) -> Drawing Explorer
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

Paul Herber

#6
Ah yes, OK. It looks like the .vsd file is corrupted somehow. I saved the file as a .vdx and the shape has now disappeared.
However, the .vsd file you sent was 400KB and the .vdx is over 1MB, so there is still something there. There are a large number of line patterns defined in the document. You probably don't need them there but the document is still 750KB.

<edit - they are line patterns - not line ends>
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

Paul Herber

I saved the file in XML format (.vdx) and had a look at it in a text editor and there is a huge lump of binary data in the VBProject section. I know this includes your macro. However, I've deleted this binary data, loaded the file back into Visio and saved it in the original .vsd format. The problem seems to have disappeared. I think there has been a corruption somewhere.

Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

wapperdude

Adding to what Paul indicates (I only have V2007), I did save as new vsd file.  Still was 400KB.  Still had error.  Although, it's a more meaning less error, does not give me any sheet.ID.  Says shape is locked against selection.

I copied the code to a new blank Visio file, ran it, runs fine.  Saved.  This new file is about 17KB as expected.  Would indeed seem to be a corrupted file.

Wapperdude
Visio 2019 Pro

chrisoft

Dear Paul,

Thanks for your feedback ! 
I have more than 50 users, I noticed this bug more and more this week. I have to investigate with them what could be at the origin of this corruption. Users found an alternative : open a new template then paste all shapes copied from the corrupted.

Dear Wapperdude,

Indeed the bug has been raised up on lane


ActiveWindow.Select shp, visSelect + visDeselectAll


The error number is different of the lane below


If shp.Type = 2 Then


it confirms definitely that I can't manage error handling in each functions as I said previously

Again, thanks both for your help