Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Using API to Sort Drawing Sheets

inulobo
Advocate

Using API to Sort Drawing Sheets

inulobo
Advocate
Advocate

I am stuck. I am not sure where I am going wrong. I am trying to sort the drawing sheets by name alphanumerically. Looking for some input. I am trying to do it with a collection.

 

 

 

Sub Sort_DrawingSheets()
    Dim drawingDoc As DrawingDocument
    'Set drawingDoc = ThisDoc.Document
    Set drawingDoc = ThisApplication.ActiveDocument
    
    Dim sheet As sheet
    Dim oSheets As Sheets
    Set oSheets = drawingDoc.Sheets
    
    Dim sheetsList As New Collection
    Set sheetsList = New Collection
    
    Dim vTemp As Variant
    
    Dim browserPane As browserPane
    Set browserPane = drawingDoc.BrowserPanes.item("Model")
    

    For Each sheet In oSheets
        sheetsList.Add (sheet.Name)
    Next

    For i = 1 To sheetsList.Count - 1
        For j = i + 1 To sheetsList.Count
            If sheetsList.item(i) > sheetsList.item(j) Then
                vTemp = sheetsList.item(j)
                sheetsList.Remove j
                sheetsList.Add vTemp, vTemp, i
            End If
        Next j
    Next i
        
    For Each sheet In sheetsList
        Dim sheetNode As BrowserNode
        Set sheetNode = browserPane.GetBrowserNodeFromObject(sheet)
        
        Dim bottomNode As BrowserNode
        Set bottomNode = browserPane.TopNode.BrowserNodes.item(browserPane.TopNode.BrowserNodes.Count)
        
        Call browserPane.Reorder(bottomNode, False, sheetNode)
    Next
    
End Sub

 

 

0 Likes
Reply
Accepted solutions (1)
664 Views
1 Reply
Reply (1)

inulobo
Advocate
Advocate
Accepted solution

Nevermind figured it out. Cannot use a regular collection needed object collection. 

0 Likes