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.
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.