Another way, tested on A2010
<CommandMethod("seltb")> _
Public Shared Sub testSelectTable()
'Dim countblocks As New Dictionary(Of KeyValuePair(Of String, Object), Long)
'Dim blkname As String
Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument()
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Try
Using tr As Transaction = db.TransactionManager.StartTransaction
Dim res As PromptSelectionResult
' change values to your suit
Dim tvs(2) As TypedValue
tvs(0) = New TypedValue(0, "acad_table")
tvs(1) = New TypedValue(1, "*title_text*")
tvs(2) = New TypedValue(410, "Layout2")
'' you can also add a filter to select table with known rows count, see DXF codes
Dim filt As SelectionFilter = New SelectionFilter(tvs)
' select all tables
res = ed.SelectAll(filt)
If res.Status <> PromptStatus.OK Then
Return
End If
For Each sobj As SelectedObject In res.Value
Dim obj As DBObject = DirectCast(tr.GetObject(sobj.ObjectId, OpenMode.ForRead, False), DBObject)
Dim tb As Table = TryCast(obj, Table)
If tb Is Nothing Then Return
Dim tbowner As BlockTableRecord = DirectCast(tr.GetObject(tb.OwnerId, OpenMode.ForRead, False), BlockTableRecord)
'if this is found the open to edit
tb.UpgradeOpen()
'display the result just for debug
Dim sb As New StringBuilder
sb.AppendLine(String.Format("---------------------------------------"))
sb.AppendLine(String.Format("Drawing name: {0}", doc.Name))
sb.AppendLine(String.Format("Tab: {0}", tbowner.Name))
Dim numrows As Integer = tb.Rows.Count
Dim numcols As Integer = tb.Columns.Count
For i As Integer = 0 To numrows - 1
Dim rowline As New List(Of String)
Dim line As String = String.Empty
For j = 0 To numcols - 1
Dim cel As Cell = tb.Cells(i, j)
rowline.Add(cel.TextString)
line = line + cel.TextString + vbTab
Next
sb.AppendLine(line.TrimEnd(vbTab))
Next
Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(sb.ToString())
''_____________________________________________________________________________''
'' rest your code is here
''_____________________________________________________________________________''
Next
tr.Commit()
End Using
Catch ex As Autodesk.AutoCAD.Runtime.Exception
Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog((ex.ToString() & vbLf) + ex.Message)
Finally
ed.WriteMessage(vbLf + "Pokey")
End Try
End Sub