Code: Select all
strRowText = tbl.Rows(lngRow).Range.Text
strRowText = UW.strNot(strRowText, Chr(13))
strRowText = UW.strNot(strRowText, Chr(7))
If 0 = Len(strRowText) Then
tbl.Rows(lngRow).Delete
Else
End If
Code: Select all
strColumnText = Selection.Text
strColumnText = UW.strNot(strColumnText, Chr(13))
strColumnText = UW.strNot(strColumnText, Chr(7))
If 0 = Len(strColumnText) Then
tbl.Columns(lngColumn).Delete
Else
End If
The first chunk of code works fine; I grab “tbl.Rows(lngRow).Range.Text” and set to work.
The second chunk of code is not so easy, there is no Word2003/VBA construct for “tbl.Columns(lngColumn).Range.Text”.
Nor does the use of Selection.Text work – that selects only one cell, not all the cells in the chosen column.
The solution for me is to write an inner loop, looping along all the cells in that column to aggregate the text.
In the meantime I ponder this. I suppose that a table’s data is stored in memory row-wise, so that obtaining the data for .Rows(i) is straightforward, but to deliver the data from .Columns(i) would involve the MSoft programmer in an inner loop, looping along all the cells in that column to aggregate the text. (Better that I do their dirty work for them!)
I get that.
At a higher level though, I can’t come up with a reason why the VBA programmer (me!) shouldn’t be able to refer to, and gain access to, .Columns(i).
The inner workings of the interpreter ought to be transparent to me. At my level I am dealing with tables, and tables consist of rows and columns. The internal implementation of the Rows and Columns ought to be irrelevant to me.
Excepting, maybe, a warning in the Advanced section that “accessing data by .Columns(i) can be measurable slower than accessing data by .Rows(i)”. This is like the old 11.5μs warnings we used to see in the Good Old Days of assembly-language programming.
Put your hand up if you have ever used “Table, Select, Column”
OK. You can all put your hands down now … Why can an end-user access columns but not the poor VBA programmer?
Code: Select all
Function strGetColumnText(tbl As Table, lngColumn As Long) As String
Dim strResult As String
Dim lngRow As Long
For lngRow = 1 To tbl.Rows.Count
strResult = strResult & tbl.Rows(lngRow).Cells(lngColumn).Range.Text
Next lngRow
strGetColumnText = strResult
'Sub TESTstrGetColumnText()
' Debug.Print strGetColumnText(Selection.Tables(1), 4)
'End Sub
End Function
Chris