How can we get the block name, the attribute values, and find how many times the block is inserted and put this information into a spreadsheet using VBA? Getting the block information from the block definition in the block table.
The following sample demonstrates this by getting all the attributes of all the block references found in model space. You need to create a simple form which contains a listbox named ListBox1 and a button that starts the following procedure:
Private Sub CommandButton1_Click() Dim elem As Object Dim block As AcadBlock Dim item As Object Dim Array1 As Variant Dim count As Integer Dim MBtest1 As String Dim str As String For Each elem In ThisDrawing.ModelSpace If elem.EntityName = "AcDbBlockReference" Then If elem.HasAttributes Then Array1 = elem.GetAttributes For count = LBound(Array1) To UBound(Array1) If (Array1(count).EntityName) = "AcDbAttribute" Then MBtest1 = Array1(count).TagString & _ " - " & Array1(count).TextString ListBox1.AddItem MBtest1 End If Next count 'Get the block definition from the block table str = elem.Name Set block = ThisDrawing.Blocks.item(str) For Each item In block str = item.EntityName 'Get the Constant attributes If item.EntityName = "AcDbAttributeDefinition" Then If item.Mode = acAttributeModeConstant Then ListBox1.AddItem item.TagString & " - " _ & item.TextString End If End If Next item End If End If Next elem End Sub