This is driving me nuts. I'm writing a function that updates existing shapes to match the new standard for the shapes, and for certain shapes I need to delete all of the existing rows in the User section and all of the rows in the action section, so that I can then repopulate these sections with different rows. Adding rows works perfectly, but I can't get deleteRow or Delete Section to work at all. The two sections of code are executing (in theory) but the function they are in crash when they get to the rebuild section because they are trying to add rows that already exist because they didn't delete. (There is a reason behind deleting and adding rows with the same name back, particularly in the action section where things have to be in order for the parent and flyout children. ) I can't figure out what I'm missing.
Originally I was planning to just delete the rows individually
Public Function RetroFitDisplayViews(shpObj As Visio.Shape, ShapeType As String, CallType As String) As String
Dim UserSectionRows As Integer
UserSectionRows = shpObj.Section(visSectionUser).Count
Dim ActionSectionRows As Integer
ActionSectionRows = shpObj.Section(visSectionAction).Count
'delete all the existing rows in the user section
For a = 1 To UserSectionRows
Call shpObj.DeleteRow(visSectionUser, a)
Next a
'delete all the existing rows in the Actions section
For b = 1 To ActionSectionRows
Call shpObj.DeleteRow(visSectionAction, b)
Next b
'rebuild the user section
This didn't work so I thought it perhaps made more sense to delete the section and then add it back but this is also not doing anything. When the functions in the SDK didn't work, I also tried recording a macro of me deleting the section manually in shape sheet and its code was pretty much the same, when I copied that from the macro in it is also not functioning. So I am at a loss now.
Dim DiagramServices As Integer
shpObj.DeleteSection visSectionUser 'this is using my object it did not work
DiagramServices = ActiveDocument.DiagramServicesEnabled ' so here I copied what the macro recorder gave me
shpObj.OpenSheetWindow
Application.ActiveWindow.Shape.DeleteSection visSectionUser 'this is literally copied from the macro recorder and it doesn't work here either
When deleting rows or any number of things, you need to start at the last count and work backwards to the 1st count. Otherwise, once you delete the first item, Visio resequences but the program moves to count #2. So, unexpected things happen.
Wapperdude
Well, I didn't figure out the problem with deleting the sections, but I did get my loop for the rows to work by always deleting position 0. (because duh the rows moved lower on the index while the index I was deleting got bigger, d'oh).
Thanks wapperdude! My brain realised my loop problem after I walked away and filled myself with cookies to drown my sorrows, but you are also my hero for the day! :-*