Macro to rename selected parts in assembly

Hello, I am working on macro which would rename selected parts in assembly. Currently i have this:

Dim swApp As Object

Dim swModel As Object

Dim swModelDocExt As Object

Dim swSelMgr As Object

Dim nbrSelections As Long

Dim thisObject As Object

Dim thisPartName As String

Dim thisPart As Object

Dim errorsRename As Long

Sub main()

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    Set swSelMgr = swModel.SelectionManager

    nbrSelections = swSelMgr.GetSelectedObjectCount2(-1)

    nbrSelections = nbrSelections - 1

    Debug.Print nbrSelections

   

    For i = 0 To nbrSelections

        Set thisObject = swSelMgr.GetSelectedObject6(i + 1, -1)

        thisPartName = thisObject.Name

        Debug.Print thisPartName

        Set thisPart = swModel.GetComponentByName(thisPartNameName)

        errorsRename = thisPart.Extension.RenameDocument("Renamed")

    Next

   

End Sub

But it throws Run-time error "91". on this line:

errorsRename = thisPart.Extension.RenameDocument("Renamed")

What am I doing wrong?

SolidworksApi macros