Error using Selection by GUID

B

Bernie

Hi,

I can select a shape by the uniqueID (GUID)

set obj = visioApp.ActivePage.Shapes.Item("GUID")

But if the GUID does not exist I get an error and the execution
stops.
How can I avoid the error.
An "On error"- construct does not work.

Thank you

Bernie
 
V

visdev1

You could try storing the GUID in a string and just test the string to see if
it is empty.

strGUID = "GUID"
if strGUID <> "" then
set obj = visioApp.ActivePage.Shapes.Item("GUID")
end if

You could also look for shapes using their name

Dim pagObj As Visio.Page
Dim shpsObj As Visio.Shapes
Dim shpobj As Visio.Shape

Set pagObj = ActivePage
Set shpsObj = pagObj.Shapes

Set shpobj = shpsObj("Sheet.9")


Or you could use just the index number but if you delete a shape then the
indexing number gets reorganized.
 
B

Bernie

I should explain more in detail what I am doing:

I store a list shapes by their valid GUIDs.
Than one of the shapes is deleted by a user in the drawing.
This GUID becomes unvalid.
If i use later my old GUID-list where one GUID is unvalid
I get the error mentioned.

What I exspect is that the returnd object is "Nothing" but not an error.

By the way the similar error happens I I use the name of the shape.
I did not test it with the index number.

Bernie
 
J

junethesecond

One idea may be ...

Sub MyTest()
Dim shp As Shape, obj As Shape
For Each shp In ActivePage.Shapes
If shp.UniqueID(visGetGUID) = _
"{D8048912-F8F1-4653-84CC-3DE2D789D06B}" _
Then
Set obj = shp
End If
Next
If obj Is Nothing Then
MsgBox "nothing"
Else
MsgBox obj.Name & " " & _
obj.UniqueID(visGetGUID)
End If
End Sub
 
J

junethesecond

Another option may be.....

Sub AnotherTest()
Dim GUID As String
Dim obj As Shape
GUID = "{D8048912-F8F1-4653-84CC-3DE2D789D06B}"
If GuidExist(GUID) Then
Set obj = ActivePage.Shapes.Item(GUID)
MsgBox obj.Name & " " & _
obj.UniqueID(visGetGUID)
Else
MsgBox "GUID not exists."
End If
End Sub
Function GuidExist(GUID As String) As Boolean
On Error GoTo ERRHAND
Dim obj As Shape
Set obj = ActivePage.Shapes.Item(GUID)
GuidExist = True
Exit Function
ERRHAND:
End Function
 
V

visdev1

You might use the Sub Document_BeforeSelectionDelete(ByVal Selection As
IVSelection) to just update your list so there are no invalid GUIDs.
 
B

Bernie

I tried to do something what you proposed but I always failed.
Now I found my error.
I forgot to clear the option "Interrupt an any error"
in my VB-environment.
So the "ON ERROR"-construct did not work in the debug-mode.

My solution is now:

Public Function GetShapeFromGUID(GUID) As Visio.Shape

On Error GoTo EndFunction
Set GetShapeFromGUID = Nothing
Set GetShapeFromGUID = visioApp.ActivePage.Shapes.Item("*" & GUID)
Exit Function

EndFunction:
End Function


Thank you for your help !!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top