How can I overwrite read only documents

Hi Everyone ,

I want to save all child assembly document.

But I can't overwrite them because they are read only state.

I made a code below

But this code returns error on  "bStatus = swCompModel.SetReadOnlyState(False)"

Please help me.

Thank you in advance.

---------------------------------------------------------------------------

Option Explicit

Sub TraverseComponent(swComp As SldWorks.Component2, nLevel As Long)

    Dim vChildCompArr             As Variant

    Dim vChildComp                 As Variant

    Dim swChildComp               As SldWorks.Component2

    Dim swCompConfig            As SldWorks.Configuration

    Dim sPadStr                       As String

    Dim i                                   As Long

    Dim sExt                             As String

    Dim nRetval                       As Long

    Dim swCompModel            As SldWorks.ModelDoc2

    Dim swApp                        As SldWorks.SldWorks

    Dim bStatus                    As Boolean

    Dim lErrors                     As Long

    Dim lWarnings                   As Long

          

    Set swApp = Application.SldWorks

    For i = 0 To nLevel - 1

        sPadStr = sPadStr + "  "

    Next i

   

    vChildCompArr = swComp.GetChildren

    For Each vChildComp In vChildCompArr

        Set swChildComp = vChildComp

                Debug.Print sPadStr & swChildComp.Name2 & " <" & swChildComp.ReferencedConfiguration & ">"

                sExt = UCase(Right(swChildComp.GetPathName, 6))

                If sExt = "SLDASM" Then

                    Set swCompModel = swApp.ActivateDoc2(swChildComp.GetPathName, False, nRetval)

                     bStatus = swCompModel.SetReadOnlyState(False)

                     bStatus = swCompModel.Save3(swSaveAsOptions_Silent, lErrors, lWarnings)

                     swApp.CloseDoc (swChildComp.GetPathName)

               Else

               End If

       

        TraverseComponent swChildComp, nLevel + 1

    Next

End Sub

Sub main()

    Dim swApp                       As SldWorks.SldWorks

    Dim swModel                     As SldWorks.ModelDoc2

    Dim swAssy                      As SldWorks.AssemblyDoc

    Dim swConf                      As SldWorks.Configuration

    Dim swRootComp              As SldWorks.Component2

    Dim bRet                        As Boolean

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    Set swConf = swModel.GetActiveConfiguration

    Set swRootComp = swConf.GetRootComponent

     Debug.Print "File = " & swModel.GetPathName

     TraverseComponent swRootComp, 1

End Sub

SolidworksApi macros