Early/late binding error VBA

Early/late binding error VBA

gifari.zulk
Participant Participant
1,059 Views
4 Replies
Message 1 of 5

Early/late binding error VBA

gifari.zulk
Participant
Participant

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.

0 Likes
Accepted solutions (1)
1,060 Views
4 Replies
Replies (4)
Message 2 of 5

norman.yuan
Mentor
Mentor
Accepted solution

Integer value for acSelectionSetAll is 5, not 4 (acSelectionSetLast). Have you tried 5?

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 5

gifari.zulk
Participant
Participant

Oh yeah it is actually 5. Thank you.

Where can I see the list of numeric value of all enumeration for my other commands?

0 Likes
Message 4 of 5

norman.yuan
Mentor
Mentor

In VBA IDE, open Object Browser, find acSelection enum and select/highlight the enum, at the botton of the Object Browser, you should see its value.

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 5 of 5

gifari.zulk
Participant
Participant

Great! Thank you again

0 Likes