- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, all. I have problem in object binding with AutoCAD using VBA. I have below early binding code which works for most computers in my office:
Sub EarlyBindingCAD()
Dim AcadApp As AcadApplication
Dim AcadDoc As AcadDocument
Set AcadApp = GetObject(, "AutoCAD.Application")
Set AcadDoc = AcadApp.ActiveDocument
'Select objects in targeted layers
SSName = [{"COLUMN","BEAM","WALL","FLOOR"}]
For i = 1 To 4
AcadDoc.SelectionSets.Item(SSName(i)).Delete
AcadDoc.SelectionSets.Add SSName(i)
FilterType(0) = 8
FilterData(0) = SSName(i)
AcadDoc.SelectionSets.Item(SSName(i)).Select acSelectionSetAll, , , FilterType, FilterData
Next i
End Sub
But few computers give compile error on first line (AcadApplication). The reference is not missing and correct (AutoCAD 2019 Type Library), the autocad variable types are even shown when typing the code. The excel's macro setting also seems correct, macros are enabled and Trust access to VBA project object model is checked.
So I tried modify the code into late binding below:
Sub LateBindingCAD()
Dim AcadApp As Object
Dim AcadDoc As Object
Set AcadApp = GetObject(, "AutoCAD.Application")
Set AcadDoc = AcadApp.ActiveDocument
'Select objects in targeted layers
SSName = Array("COLUMN","BEAM","WALL","FLOOR")
For i = 0 To 3
AcadDoc.SelectionSets.Item(SSName(i)).Delete
AcadDoc.SelectionSets.Add SSName(i)
FilterType(0) = 8
FilterData(0) = SSName(i)
AcadDoc.SelectionSets.Item(SSName(i)).Select acSelectionSetAll, , , FilterType, FilterData
Next i
End Sub
Now it can connect/bind the AutoCAD object, but still gives compile error in last line (select all). This is because the acSelectionSetAll is enumeration that still needs to refer to AutoCAD reference before running. I tried replace this enumerate with integer, for example 4, but not working (does not select all in filtered layer).
Anyone have suggestion?
Thank you in advance.
Solved! Go to Solution.