Is there any way to delete blank rows in the Page.Layers section. This code identifies the blank row, but won't delete the row.
Public Sub DeleteBlankLayerRow()
Dim vsoPage As Visio.Page
Set vsoPage = ActivePage
Dim vsoShape As Visio.Shape
Set vsoShape = vsoPage.PageSheet
Dim intRows As Integer
intRows = vsoShape.RowCount(Visio.visSectionLayer)
Dim i As Integer
Dim LayerName As String
For i = 1 To intRows
LayerName = vsoShape.CellsSRC(visSectionLayer, i, visLayerName).Formula
If LayerName = "" Then
vsoShape.DeleteRow Visio.visSectionLayer, i
End If
Next
End Sub
Any help would be greatly appreciated!
Just because a row has a blank name doesn't mean that the layer is empty or unused.
Layers are a property of the page, they have to be deleted from the page. Deleting a leyer that is used by a shape will also delete that shape.
The problem would appear to be your Dim declaration. Below are 2 macros that successfully delete a layer row. They both assume the desired row has been identified.
Keep in mind Paul's warning.
Sub Macro1()
'This works by opening the Layer Properties window for the active page.
'Note, the Layer Properties window has option to remove ALL unreferenced layers.
'Item count below begins with "1", not "0".
'The order of rows does not necessarily correspond to the item number???
Dim vsoLayer1 As Visio.Layer
Set vsoLayer1 = Application.ActiveWindow.Page.Layers.Item(3)
vsoLayer1.CellsC(visLayerLock).FormulaU = "0"
vsoLayer1.Delete 1
End Sub
Sub Macro2()
'This is run with no shapes selected,and works with the active window.
ActiveWindow.Page.PageSheet.OpenSheetWindow
ActiveWindow.Shape.DeleteRow visSectionLayer, 2 'Row count starts with "0", not "1"; this is 3rd row.
End Sub
The macro recorder is your friend.
Wapperdude