Run-time Error '9' Subscript out of Range

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I created VBA code to extract Dynamic Block Property, but occur error "Run-time Error '9' Subscript out of Range". Please help me fix it. Tks All.
Sub EXtract_Table()
Dim oSset As AcadSelectionSet
Dim oEnt As AcadEntity
Dim oBlk As AcadBlockReference
Dim varPt As Variant
Dim ftype(0) As Integer
Dim fdata(0) As Variant
Dim k, bName As String
Dim xStr As String
Dim yStr As String
Dim i As Integer, j As Integer
Dim l As Integer
Dim aName As Variant
ftype(0) = 0: fdata(0) = "INSERT"
Dim dxfCode, dxfValue
dxfCode = ftype: dxfValue = fdata
With ThisDrawing.SelectionSets
While .Count > 0
.Item(0).Delete
Wend
Set oSset = .Add("$Blocks$")
End With
ThisDrawing.ActiveSpace = acModelSpace
oSset.SelectOnScreen dxfCode, dxfValue
ThisDrawing.ActiveSpace = acModelSpace
Dim paSpace As AcadModelSpace
Set paSpace = ThisDrawing.ModelSpace
varPt = ThisDrawing.Utility.GetPoint(, "Specify insertion point: ")
Dim oTable As AcadTable
Set oTable = paSpace.AddTable(varPt, oSset.Count + 2, 5, 0.3, 1.5)
ZoomExtents
With oTable
.RegenerateTableSuppressed = True
.SetCellTextHeight i, j, 0.09375
.SetCellAlignment i, j, acMiddleCenter
.SetCellType i, j, acTextCell
.SetText 0, j, "HG"
.SetCellTextHeight i, j + 2, 0.09375
.SetText 0, j + 2, "ID"
.SetCellTextHeight i, j + 4, 0.09375
.SetText 0, j + 4, "ID"
.SetText 1, j + 1, "X"
.SetCellTextHeight 1, j + 1, 0.09375
.SetText 1, j + 2, "Y"
.SetCellTextHeight 1, j + 2, 0.09375
.SetText 1, j + 3, "Z"
.SetCellTextHeight 1, j + 3, 0.09375
l = oSset.Count - 1
ReDim aName(0 To l) As Variant
For i = 0 To oSset.Count - 1
Set oEnt = oSset.Item(i)
Set oBlk = oEnt
If oBlk.IsDynamicBlock Then
bName = oBlk.EffectiveName
Else
bName = oBlk.Name
End If
aName = oBlk.GetAttributes
k = aName(i).TextString
xStr = Format(CStr(Round(oBlk.InsertionPoint(1), 3)), "#0.000")
yStr = Format(CStr(Round(oBlk.InsertionPoint(0), 3)), "#0.000")
.SetCellTextHeight i, j, 0.09375
.SetCellAlignment i, j, acMiddleCenter
.SetText i + 2, j, k
.SetCellTextHeight i + 2, j, 0.09375
.SetText i + 2, j + 1, xStr
.SetCellTextHeight i + 2, j + 1, 0.09375
.SetText i + 2, j + 2, yStr
.SetCellTextHeight i + 2, j + 2, 0.09375
Next i
.RegenerateTableSuppressed = False
.Update
End With
End Sub