[VBA] Shape data

Started by Ralli, March 15, 2016, 07:49:04 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Ralli

Hi there,


i'm just learning VBA with Visio. (i know it from Excel already a little).

Now I have a problem when reading and comparing Shape data.

Background:
- create 5 shapes (without VBA)
- each shape is assigned with a unique ID (50 to 54)
- linking an Excel spreadsheet and let automatically using this ID assign



The Problem:
The code searches in the shape data and compares the ID with another field in the datas. If he finds it, the shape is marked. This works well up to this point.


When I add new shapes (ID 1 to 49), the Code seeks unfortunately still only in the data of the last 5 shapes.
I use "for each ... next"!!

If i just use the same loop only with fill the foreground, then all shapes are searched and filled.
When I combine both - fill foreground and search in shape date - only the last 5 shapes is used.



What is wrong here??


Thanks for your help
Ralph


EDIT: .. the code
Dim Shape_Q As Visio.Shape
Dim Q_ID, Q_Ziel As String

Set Shape_Q = ActiveWindow.Selection(1)
' Port-ID
Q_ID = Shape_Q.Cells("Prop.Identifier").Formula
' Dest-ID
Q_Ziel = Shape_Q.Cells("Prop.Row_14").Formula

....

Dim shp_ID As Visio.Shape
Dim pagShape As Visio.Shape
Set pagShape = Visio.ActivePage.PageSheet

For Each shp_ID In ActivePage.Shapes
    ' read ID
    Z_ID = shp_ID.Cells("Prop.Identifier").Formula
    ' ID = Dest -> red Shape
    If (Q_Ziel = Z_ID) Then
        shp_ID.Cells("fillforegnd").Formula = 3
        Exit Sub
    End If
Next shp_ID

Thomas Winkel

Hi,

please post a minimized visio document that shows the effect.

Your code will crash on the following line as soon as it reaches a shape without the property "Identifier".
QuoteZ_ID = shp_ID.Cells("Prop.Identifier").Formula

Unless you are sure that a cell exists you should check it before you access it:

If shp_ID.CellExists("Prop.Identifier", Visio.visExistsAnywhere) Then
    Z_ID = shp_ID.Cells("Prop.Identifier").Formula
End If


Regards,
Thomas