Hi,

I have been using an excel macro which opens and automates AutoCAD drawings for about a year now, we recently bought 3 new computers with AutoCAD Mechanical 2016 and office 2016 installed.
Every time I run the macro it would hit an immediate error : 2147319779 : automation error library not registered, this happens with all 3 computers.

The macro is designed to detect the correct autoCAD version and add the correct references.
I have checked in VB > tools > references all required references have been ticked, but the error would still appear upon running the macro.

I have tried:
- uninstall and reinstall excel and autoCAD
- formatting the computer and reinstalling everything
- replacing the AutoCAD references with files form a working computer
- checked in REGEDIT for {00020813-0000-0000-C000-000000000046} which shows 1.9 as the correct reference for my excel.
- I also wrote different codes to check if the AutoCAD reference has actually been found and added, the answer is yes (The references are always ticked after the error occurs).

Please find below the functions and references I use for the macro:
references used.png

Function SetAutoCADReferences(acadVersion As Long, Optional errMsg As Variant, Optional errMsgPremise As Variant) As Boolean

    Dim VBAEditor As VBIDE.VBE
    Dim vbProj As VBIDE.VBProject
    Dim vbProjRef As VBIDE.Reference

    Set VBAEditor = Application.VBE
    Set vbProj = ThisWorkbook.VBProject

    Dim okAutoCAD As Boolean, _
        okSymBBAuto As Boolean, _
        okAcadmAuto As Boolean

    If IsMissing(errMsgPremise) Then errMsgPremise = vbNullString

    On Error GoTo SafeExit

    'remove broken or AutoCAD existing references
    For Each vbProjRef In vbProj.References
        If vbProjRef.IsBroken Then
            vbProj.References.Remove vbProjRef
        Else
            Select Case vbProjRef.name
            End Select
        End If
    Next

    'try adding AutoCAD updated references
    okAutoCAD = AddReference(vbProj, "C:\Program Files\Common Files\Autodesk Shared\acax", "enu.tlb")
    okSymBBAuto = AddReference(vbProj, "C:\Program Files\Common Files\Autodesk Shared\SymBBAuto", "ENU.tlb")
    okAcadmAuto = AddReference(vbProj, "C:\Program Files\Common Files\Autodesk Shared\AcadmAuto", ".tlb")

    'check it worked
    For Each vbProjRef In vbProj.References
        Select Case vbProjRef.name
            Case "AutoCAD"
                okAutoCAD = True
                Debug.Print "found reference '" & vbProjRef.name & "' at: " & vbProjRef.FullPath
                
                acadVersion = Split(Split(vbProjRef.FullPath, "acax")(1), "enu")(0)

            Case "SymBBAuto"
                okSymBBAuto = True
                Debug.Print "found reference '" & vbProjRef.name & "' at: " & vbProjRef.FullPath

            Case "AcadmAuto"
                okAcadmAuto = True
                Debug.Print "found reference '" & vbProjRef.name & "' at: " & vbProjRef.FullPath

        End Select
    Next

    SetAutoCADReferences = okAutoCAD And okSymBBAuto And okAcadmAuto

    Exit Function

SafeExit:
    If IsMissing(errMsg) Then
        MsgBox Translate("Error in") & " 'SetAutoCADReferences()'" _
                & vbCrLf & errMsgPremise _
                & vbCrLf & err.Number & " - " & err.Description, , "BOMtoExcel"
    Else
        errMsg = Translate("Error in") & " 'SetAutoCADReferences()'" _
                 & vbCrLf & errMsgPremise _
                 & vbCrLf & err.Number & " - " & err.Description
    End If

End Function
---------------------------------------------------------------------------------------------------------------
Function AddReference(vbProj As VBIDE.VBProject, prefix As String, suffix As String) As Boolean

    Dim startingVersion As Long
        startingVersion = ACAD_HIGHEST_VERSION + 1

    Dim subVersions As Variant
        subVersions = Array("", ".0", ".1", ".2")
    Dim iSubVersion As Long
    Dim subVersion As String

    On Error Resume Next
    Do
        startingVersion = startingVersion - 1

        iSubVersion = LBound(subVersions) - 1
        Do
            iSubVersion = iSubVersion + 1
            err.Clear

            vbProj.References.AddFromFile prefix & startingVersion & subVersions(iSubVersion) & suffix
        Loop While err.Number <> 0 And iSubVersion < UBound(subVersions)

    Loop While err.Number <> 0 And startingVersion > 1

    AddReference = err.Number = 0 And startingVersion > 1
    If AddReference Then Debug.Print "added reference: "; prefix & startingVersion & subVersions(iSubVersion) & suffix
End Function
I have been trying to figure this out for weeks now and looked everywhere I could but had no luck, I would be really appreciated if anyone could help me with this , thanks.

Cary