Find a Shape anywhere by the name thats displayed in Drawing Explorer?

Started by Ginge, July 31, 2009, 07:42:57 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Ginge

Hey guys,

Sorry for asking the question again if it's already been asked (or because it's probably a simple answer haha).

For example what I have is shapes on sheet 1 say called 1A,1B,1C and sheet 2 will have shapes on it called 2A,2B,2C and so on etc.

When I drop a different shape on a random page, I reference it to 1A on sheet 1 by using shape data. Using the shape data I enter, I would like to see if shape 1A on sheet 1 exists and if it does add "1" to to a value within the shape sheet in the shape 1A.

My question is how can I find a shape (knowing the sheet its on & the shape name) and know if it exists?

Any help would be appreciated.

Thanks, Ginge

aledlund

the thing your faced with is if you attempt to access a shape that does not exist, then Visio throws an error. So to get around it you wrap the assign in an error catcher (on error resume next, or try-catch-endtry).
hth
al




Private Sub CheckShape()

Dim visPage As Visio.Page
Dim visShape As Visio.Shape

Set visPage = Application.ActivePage
' might come back with an error
On Error Resume Next
Set visShape = visPage.Shapes("sheet.1")
' put your error handler back
On Error GoTo errHandler

If visShape Is Nothing Then
    MsgBox "shape not there"
Else
    MsgBox "did my work"
End If

Exit Sub

errHandler:

    Debug.Print Err.Description

End Sub