Assign array value from late binded object (VBA)

gifariz

Board Regular
Joined
May 2, 2021
Messages
128
Office Version
  1. 365
Platform
  1. Windows
Hi, all. I have problem in late binding code. Because early binding gives compile error (even reference seems correct) so I am moving to late binding in my code.
Here is my sample code:
VBA Code:
Sub LateBindingCAD()

'Declaration and late binding the application objects
Dim AcadApp As Object
Dim AcadDoc As Object
Dim AcadObj As Object
Dim LineObj As Object
Dim LineLayers(), LineCoords()
Dim i
Set AcadApp = GetObject(, "AutoCAD.Application")
Set AcadDoc = AcadApp.ActiveDocument

'Select objects in targeted layers, works fine, not important to the question
    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 5, , , FilterType, FilterData
    Next i

'Extract data from selected object, by late binding the objects inside application objects
    ReDim LineLayers(100), LineCoords(100)
    i = 0
    For Each SSObj In AcadDoc.SelectionSets
        For Each AcadObj In SSObj
            If AcadObj.Layer = "COLUMN" And AcadObj.ObjectName = "AcDbLine" Then
                Set LineObj = AcadObj
                LineLayers(i) = LineObj.Layer
                LineCoords(i) = LineObj.StartPoint(0) 'error here <------------------------------------------------------------------
                i = i + 1
            End If
        Next
    Next

End Sub

The error occurs in almost last line: "LineCoords(i) = LineObj.StartPoint(0)", the error is "Run-time error '451': Property let procedure not defined and property get procedure did not return an object".
Assigning values for non-array type of this object works fine, for example the "LineLayers(i) = LineObj.Layer" works fine.
The "LineObj.StartPoint" is Double type with size of (0 To 2).

I tried couple things, but failed:
VBA Code:
'Variant array type direct assignment
Dim StartPoint()
StartPoint = LineObj.StartPoint 'error here
LineCoords(i) = StartPoint(i)

'Dummy late binding object
Dim StartPoint As Object
Set StartPoint = LineObj.StartPoint 'error here
LineCoords(i) = StartPoint(i)

Any suggestion?
Thank you in advance.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Your code:
i=0
then LineLayers(i) and LineCooords(i)
fail with first i=0

May be let i starts from 1
i=1
 
Upvote 0
Your code:
i=0
then LineLayers(i) and LineCooords(i)
fail with first i=0

May be let i starts from 1
i=1
Thank you but it doesn't work. i is just counter. The problem is getting value from the array of object. So, even without iteration like "x = LineObj.StartPoint(0)" also produce same error '451'.
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,160
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top