Exclude Shapes from Shape report

Started by longo93, July 06, 2016, 07:40:17 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

longo93

Hey guys,

i wrote a macro to get shape datas to an excel file. Now i want to exclude some Shapes who has no Datas. My vba code to get the shape datas and wrote them into an excel file is to long so i just show you the important thing. how can i exclude now shapes with no "NameDE" excel always give me a space line instead of doing nothing.

For Each shp In ActivePage.Shapes
    If shp.OneD Then
   
    Else
     i = i + 1
      If shp.CellExists("prop.ShapeNumber", True) Then
         blatt.Cells(i, 1).Value = shp.Cells("prop.ShapeNumber").Result("")
      Else
        blatt.Cells(i, 1).Value = ""
      End If
     
     blatt.Cells(i, 2).Value = shp.Cells("prop.NameDE").ResultStr("")
     
      If shp.CellExists("prop.Typ", True) Then
        blatt.Cells(i, 3).Value = shp.Cells("prop.Typ").ResultStr("")
      Else
        blatt.Cells(i, 3).Value = ""
      End If
     End If

wapperdude

Is the prop.namede the only  shape ignore criteria?

You could add cell exists test along with the shape OneD test.  If either fail, next shape, else, do your shape processing.

Wapperdude
Visio 2019 Pro

longo93

#2
yes just the namede, the other criterias are already ignored if they are not set. i already tried it with
if shp.cellexsits("prop.namede", true) then
Else
blatt.cell ....

but it is not working i dont know why

wapperdude

#3

It's how you setup the "IF" statement.  The construct is:

   If (test criteria) then
          Execute this code because criteria passed
    Else
          Execute this code because criteria failed
    End if

For your case, pseudo code...

FOR shapes on the page
.
.
    If shape is Not OneD AND  shapecell exists Then
           processing code to fetch  shapesheet info and send to Excel
    End if
.
.
Next

The if statement rejects 1D shapes  or shapes that don't have desired cell and goes to next shape.  However, if shape is 2D and has desired cell, then execute the processing code.

Anyway, that's the basic idea.
HTH
Wapperdude
Visio 2019 Pro

longo93

Hey Wapperdude,

thanks for your reply. Well i tried what you suggested but if i do so my excel file has no datas anymore  :-[

Well actually my problem is, that i´m giving my shape 3 types of data:

1. ShapeNumber
2. NameDE
3. Typ

The property ShapeNumer is automatically created with the addon from microsoft to enumerate shapes. i think there is the beginning of my problem because that addon enumerates all shapes on my paper, also text fields and helplines. With my macro, u see below, i fetch up all these datas in an excel file and create a empty row but with the ShapeNumber that has given from visio it looks in the excel file like:

1.     
2.                       CorrectName                            CorrectTyp
3.                       CorrectName                            CorrectTyp
4.
5.

This is e.g. if i have 2 shapes of my stencil on my paper and 2 text fields and 1 helpline. Do you have any idea how i exclude everything except that shapes of my stencil from the numbering addon ?

For Each shp In ActivePage.Shapes
    If shp.OneD Then
   
    Else
     i = i + 1
      If shp.CellExists("prop.ShapeNumber", True) Then
         blatt.Cells(i, 1).Value = shp.Cells("prop.ShapeNumber").Result("")
      Else
        blatt.Cells(i, 1).Value = ""
      End If
     
       blatt.Cells(i, 2).Value = shp.Cells("prop.NameDE").ResultStr("")
     
      If shp.CellExists("prop.Typ", True) Then
        blatt.Cells(i, 3).Value = shp.Cells("prop.Typ").ResultStr("")
      Else
        blatt.Cells(i, 3).Value = ""
      End If
     
     End If
   
Next

longo93

Well actually i fixed my problem. i´m able now to exclude everything which is not part of my stencil. therefore i´m using follow code ...

For Each shp In ActivePage.Shapes
    If shp.OneD Then
   
      Else
       i = i + 1
      If shp.CellExists("prop.NameDE", False) Then
       blatt.Cells(i, 1).Value = shp.Cells("prop.ShapeNumber").Result("")
       blatt.Cells(i, 2).Value = shp.Cells("prop.NameDE").ResultStr("")
            If shp.CellExists("prop.Typ", True) Then
             blatt.Cells(i, 3).Value = shp.Cells("prop.Typ").ResultStr("")
            Else
            End If
      Else
      End If
      End If
   
Next