PDA

View Full Version : Can't locate bug of a Run-time error '438' message



harukint
07-28-2014, 02:39 PM
Code:


Public excelApp As Object
Public wkbObj As Object
Public shtObj As Object
Sub CommandButton1_Click()
Dim i, j, btot As Integer
Dim bnam As String
Dim ent As Object
btot = ThisDrawing.Blocks.Count
For i = 0 To btot - 1
bnam = ThisDrawing.Blocks.Item(i).Name
If Not Mid$(bnam, 1, 1) = "*" Then ListBox1.AddItem bnam
Next i
For i = 0 To ListBox1.ListCount - 1
bnam = ListBox1.List(i): btot = 0
For j = 0 To ThisDrawing.ModelSpace.Count - 1
Set ent = ThisDrawing.ModelSpace.Item(j)
If ent.EntityType = aeBlockReference And ent.Name = bnam Then btot = btot + 1
Next j
ListBox2.AddItem btot
Next i
End Sub

------------------------------------
The red line is where the problem occurs.
I'm on AutoCAD with EXCEL 14 library
I figure this should be a pretty general code, would like to use the code to count blocks in AutoCAD and then pass the value to EXCEL.

Bob Phillips
07-28-2014, 03:28 PM
I presume that aeBlockReference is a library constant, do you have a reference to that library? What happens if you substitute the constant's value in there?

Aflatoon
07-29-2014, 05:05 AM
438 means you're using a property or method that doesn't exist. Are you sure EntityType is correct?

Tommy
07-30-2014, 06:05 AM
This:

If ent.EntityType = aeBlockReference And ent.Name = bnam Then btot = btot + 1
Should be:

If TypeOf ent Is AcadBlockReference And ent.Name = bnam Then btot = btot + 1