I want to make an old macrocode a new macrocode

Please tell me.

Please change this macrocode into the cord which is readable in SolidWorks2020

We would greatly appreciate your response.

Dim intDocType As Integer
        Dim intVersion As Integer
        Dim intOptions As Integer
        Dim intErrors As Integer
        Dim intWarnings As Integer
        Dim blnRetval As Boolean

        If ParentModelDoc2.GetType = swDocumentTypes_e.swDocASSEMBLY Then
            Dim swConfMgr As SldWorks.ConfigurationManager = ParentModelDoc2.ConfigurationManager
            Dim swConf As SldWorks.Configuration = swConfMgr.ActiveConfiguration
            Dim swComp As SldWorks.Component2 = swConf.GetRootComponent
            Dim CiledCompornents() As Object = swComp.GetChildren()
            If CiledCompornents.Length > 0 Then
                For i As Integer = 0 To CiledCompornents.GetUpperBound(0)

                    Dim CiledCompornent As SldWorks.Component2 = CiledCompornents(i)
                    Dim CiledFilePath As String = CiledCompornent.GetPathName
                    Dim CiledFileExtention As String = New FileInfo(CiledFilePath).Extension.ToLower.Replace(".", "")
                    Select Case CiledFileExtention
                        Case "sldprt" : intDocType = swDocumentTypes_e.swDocPART
                        Case "sldasm" : intDocType = swDocumentTypes_e.swDocASSEMBLY
                        Case "slddrw" : intDocType = swDocumentTypes_e.swDocDRAWING
                    End Select
                    intOptions = swOpenDocOptions_e.swOpenDocOptions_Silent Or swOpenDocOptions_e.swOpenDocOptions_AutoMissingConfig
                    intErrors = 0
                    intWarnings = 0
                    Dim swModelDoc2 As SldWorks.ModelDoc2 = swApp.OpenDoc6(CiledFilePath, intDocType, intOptions, "", intErrors, intWarnings)
                    If intWarnings = SwConst.swFileLoadWarning_e.swFileLoadWarning_AlreadyOpen Then
                        swModelDoc2 = swApp.ActivateDoc2(CiledFilePath, True, intErrors)
                    End If
                    My.Application.DoEvents()

                    Call SaveComponentDiver(swModelDoc2)

                    swModelDoc2 = Nothing
                    CiledCompornent = Nothing
                Next
            End If
            CiledCompornents = Nothing
            swComp = Nothing
            swConf = Nothing
            swConfMgr = Nothing
        End If


        ParentModelDoc2.ForceRebuild3(True)
        My.Application.DoEvents()

        Dim FileName As String = ""
        If ParentModelDoc2.GetPathName <> "" Then
            FileName = New FileInfo(ParentModelDoc2.GetPathName).Name
        Else
            Select Case ParentModelDoc2.GetType
                Case swDocumentTypes_e.swDocPART : FileName = ParentModelDoc2.GetTitle & ".sldprt"
                Case swDocumentTypes_e.swDocASSEMBLY : FileName = ParentModelDoc2.GetTitle & ".sldasm"
                Case swDocumentTypes_e.swDocDRAWING : FileName = ParentModelDoc2.GetTitle & ".slddrw"
            End Select
        End If
        Dim FilePath As String = TextBox1.Text.TrimEnd("\\") & "\\" & FileName

        intVersion = swSaveAsVersion_e.swSaveAsCurrentVersion
        intOptions = swSaveAsOptions_e.swSaveAsOptions_Silent
        blnRetval = ParentModelDoc2.SaveAs4(FilePath, intVersion, intOptions, intErrors, intWarnings)
        My.Application.DoEvents()

        swApp.CloseDoc(ParentModelDoc2.GetTitle)
        ParentModelDoc2 = Nothing
        My.Application.DoEvents()

SolidworksApi/macros
Answers 2
AJ
AJ 2021-04-08 Best Answer

Your problem is probably not in the code it's in at Tools > References assuming the UI stuff is taken care of. You might have some missing references. Browse to your sw installation folder and find slworks.tlb and swconst.tlb from the References window.

Best,
Amen
www.bluebyte.biz

TS
TS 2021-04-08

Looks some kind of mix of codes to me. Tried to compile with VBA editor and got following (commented rows not working) so you need to fix those lines ... 

Set swApp = Application.SldWorks
Dim swModelDoc2 As SldWorks.ModelDoc2
Dim FileName As String
Dim FilePath As String

Dim swConfMgr As SldWorks.ConfigurationManager
Dim swConf As SldWorks.Configuration
Dim swComp As SldWorks.Component2
Dim CiledCompornents() As Object

Dim CiledCompornent As SldWorks.Component2
Dim CiledFilePath As String
Dim CiledFileExtention As String

Dim intDocType As Integer
Dim intVersion As Integer
Dim intOptions As Integer
Dim intErrors As Integer
Dim intWarnings As Integer
Dim blnRetval As Boolean

Dim i As Integer


If ParentModelDoc2.GetType = swDocumentTypes_e.swDocASSEMBLY Then

Set wConfMgr = ParentModelDoc2.ConfigurationManager
Set swConf = swConfMgr.ActiveConfiguration
Set swComp = swConf.GetRootComponent
CiledCompornents = swComp.GetChildren()

If UBound(CiledCompornents) > 0 Then

For i = 0 To UBound(CiledCompornents)

Set CiledCompornent = CiledCompornents(i)
CiledFilePath = CiledCompornent.GetPathName
'CiledFileExtention = New FileInfo(CiledFilePath).Extension.ToLower.Replace(".", "")

Select Case CiledFileExtention
Case "sldprt": intDocType = swDocumentTypes_e.swDocPART
Case "sldasm": intDocType = swDocumentTypes_e.swDocASSEMBLY
Case "slddrw": intDocType = swDocumentTypes_e.swDocDRAWING
End Select

intOptions = swOpenDocOptions_e.swOpenDocOptions_Silent Or swOpenDocOptions_e.swOpenDocOptions_AutoMissingConfig
intErrors = 0
intWarnings = 0
Set swModelDoc2 = swApp.OpenDoc6(CiledFilePath, intDocType, intOptions, "", intErrors, intWarnings)

If intWarnings = SwConst.swFileLoadWarning_e.swFileLoadWarning_AlreadyOpen Then
swModelDoc2 = swApp.ActivateDoc2(CiledFilePath, True, intErrors)
End If

'My.Application.DoEvents()


'Call SaveComponentDiver(swModelDoc2)

swModelDoc2 = Nothing
CiledCompornent = Nothing

Next

End If

'CiledCompornents = Nothing
swComp = Nothing
swConf = Nothing
swConfMgr = Nothing
End If


ParentModelDoc2.ForceRebuild3 (True)
'My.Application.DoEvents()

FileName = ""

If ParentModelDoc2.GetPathName <> "" Then
'FileName = New FileInfo(ParentModelDoc2.GetPathName).Name
Else

Select Case ParentModelDoc2.GetType
Case swDocumentTypes_e.swDocPART: FileName = ParentModelDoc2.GetTitle & ".sldprt"
Case swDocumentTypes_e.swDocASSEMBLY: FileName = ParentModelDoc2.GetTitle & ".sldasm"
Case swDocumentTypes_e.swDocDRAWING: FileName = ParentModelDoc2.GetTitle & ".slddrw"
End Select
End If

FilePath = TextBox1.Text.TrimEnd("\") & "\" & FileName

intVersion = swSaveAsVersion_e.swSaveAsCurrentVersion
intOptions = swSaveAsOptions_e.swSaveAsOptions_Silent
blnRetval = ParentModelDoc2.SaveAs4(FilePath, intVersion, intOptions, intErrors, intWarnings)

'My.Application.DoEvents()

swApp.CloseDoc (ParentModelDoc2.GetTitle)
ParentModelDoc2 = Nothing
'My.Application.DoEvents()