>I need some help making the below script a little smarter. I wish to have
>the
[quoted text clipped - 32 lines]
> Next oTbl
> End Sub
Dave,
It appears that this does work but only for the first table. I need to
implement this within the loop so that all the tables throughout the document
get validated. I have tried the below which I believe is close but the
Range.Text variable is being populated with the entire contents of the table
and not just the first cell. If I can figure how to get the first cell to be
read in (only), I should be good to go.
(Shouldn’t it be something like .Cells(1,1).Range.Text = “Mike” ?)
Sub ResizeTablesWith4columns()
Dim oTbl As Table
For Each oTbl In ActiveDocument.Tables
With oTbl
If .Range.Text = "Mike" And oTbl.Columns.Count = 4 Then
MsgBox "True" .
End If
End With
Next oTbl
End Sub
> Hi,
>
[quoted text clipped - 53 lines]
> > Next oTbl
> > End Sub
Dave Lett - 16 Mar 2006 22:08 GMT
Hi,
No, it should ABSOLUTELY not be .Cells(1,1).Range.Text = "Mike".
Remember, the cell(1,1) and every cell in every table has an "end of cell"
marker. So, while you see "Mike" the .Range.Text of the cell is "Mike" &
EndOfCellCharacter (actually it's two characters). Try this instead:
Dim oTbl As Table
Dim iTbl As Integer
Dim oCl As Cell
Dim oRng As Range
For iTbl = ActiveDocument.Tables.Count To 1 Step -1
Set oTbl = ActiveDocument.Tables(iTbl)
Set oCl = oTbl.Cell(1, 1)
Set oRng = oCl.Range
oRng.MoveEnd Unit:=wdCharacter, Count:=-1
If oTbl.Columns.Count = 4 And oRng.Text = "Mike" Then
MsgBox "True"
End If
Next iTbl
HTH,
Dave
> Dave,
>
[quoted text clipped - 84 lines]
>> > Next oTbl
>> > End Sub