After much scratching of heads...
Your routine does not work with tables that have vertically merged cells!
If you try to access "Rows(i)" information in such a table, it makes Word
CRASH - no soft option here I'm afraid!!
Here is a function that has stripped me of several months of life expectancy
to develop......
I'll leave it to you to work out where the email program has forced a line
break.....
Function WidthofTable(myTable As Table)
'Can't do rows on tables with vertically merged cells
Dim x1, x2
Dim r1, r2
Dim i, j
x1 = 0: x2 = 0
r1 = 0: r2 = 0
i = 0
WidthofTable = 0
j = myTable.Range.Cells.count
myTable.Cell(1, 1).Select
With Selection
.Collapse direction:=wdCollapseStart
x1 = .Information(wdHorizontalPositionRelativeToPage)
r1 = .Information(wdStartOfRangeRowNumber)
For i = 1 To j
myTable.Range.Cells(i).Select
If i < j Then
r2 = .Information(wdStartOfRangeRowNumber)
If r2 > r1 Then
r1 = r2
myTable.Range.Cells(i - 1).Select
.Collapse direction:=wdCollapseEnd
If .Information(wdHorizontalPositionRelativeToPage) > x2
Then
x2 = .Information(wdHorizontalPositionRelativeToPage)
End If
myTable.Range.Cells(i).Select
End If
Else
ActiveDocument.Range(Start:=.Range.End - 1, End:=.Range.End -
1).Select
If .Information(wdHorizontalPositionRelativeToPage) > x2 Then
x2 = .Information(wdHorizontalPositionRelativeToPage)
End If
End If
Next
End With
WidthofTable = x2 - x1
'MsgBox (x2 - x1)
End Function
--------------------------------------------------------------------
Jeff Hall MSc MRICS
Director, Eon Commerce Ltd.
http://www.eon-commerce.com
Software available for you to evaluate before buying...
EasyHTML/Help CHM file Editor for MS Word
http://www.easyhtmlhelp.com