Author Topic: How to quickly delete shape data  (Read 17255 times)

0 Members and 1 Guest are viewing this topic.

MikeB

  • Newbie
  • *
  • Posts: 1
Re: How to quickly delete shape data
« Reply #15 on: May 14, 2018, 10:18:58 AM »
Just to take this a bit further :-)

...how can I delete all shape data in collection of shape apart from one specific field? i.e. I have about 200 shapes that all have the same fields - the first field is named 'AppID' and I want to keep this but delete all others. I guess I have to access at row name and test against that to exclude it?

Any help welcome :-)

Surrogate

  • Hero Member
  • *****
  • Posts: 887
    • ShapeSheet™ Knowledge Base
Re: How to quickly delete shape data
« Reply #16 on: May 14, 2018, 06:34:12 PM »
Try this code please
Code: [Select]
Sub MikeB()
Dim shp As Shape ' current shape
Dim sc As Section ' shp's shape data section
Dim rw As Row ' row in shape data section
Dim cnt As Integer ' count or rows in shape data section
Dim r As Integer ' counter
For Each shp In ActivePage.Shapes
If shp.SectionExists(visSectionProp, visExistsAnywhere) Then
' check for shape data section exist for current shape
Set sc = shp.Section(visSectionProp)
' define shape data section variable
cnt = sc.Count
' define how many rows in shape data section
For r = cnt - 1 To 1 Step -1
'iterate rows in section from last to second
' first row in Shape Data section don't delete
' rows index in Visio start from 0 !
Set rw = sc.Row(r)
' define row in shape data section variable
shp.DeleteRow sc.Index, rw.Index
' delete row in shape data section
Next
End If
Next
End Sub