Recorded a macro to set the table width:
Selection.Tables(1).Select
Selection.Tables(1).PreferredWidthType = wdPreferredWidthPoints
Selection.Tables(1).PreferredWidth = InchesToPoints(5)
Maybe that'll help you get what you need? Realizing of course that you'd
probably write it much more efficiently.
Anyway, just wanted to show you that tables have a Width too.
************
Anne Troy
www.OfficeArticles.com
>I need to determine the width of tables prior to copy them into a 2 column
> document using VBA. I looked at the columns width property but not all
[quoted text clipped - 6 lines]
> Thanks!
> Jerry
JWS315 - 26 Oct 2005 22:53 GMT
Anne,
I tried the same code, however if you add the line:
msgbox Selection.Tables(1).PreferredWidth
it returns the value 999999 for any table that has merged cells.
I am able to set the width OK but avnnot find a way to return the value
properly - any thoughts?
Thanks - jerry
> Recorded a macro to set the table width:
> Selection.Tables(1).Select
[quoted text clipped - 17 lines]
> > Thanks!
> > Jerry
JWS315 was telling us:
JWS315 nous racontait que :
> I need to determine the width of tables prior to copy them into a 2
> column document using VBA. I looked at the columns width property
[quoted text clipped - 3 lines]
> Is there an easy way to detemine the width of any table regardless of
> the columns?
There are two problems, one for which I can offer a solution and the other I
cannot...
First, if the table has columns that have user-set width, .PreferredWidth
will return 999999. This can be detected and we can get around that, as in
my example below.
Second, if you encounter the first case and then have to use the workaround,
if there are merged cells in the table, it is possible that an error be
generated.
'_______________________________________
Option Explicit
'_______________________________________
Sub GetNormalWidth()
Dim TableWidthType As Long
Dim TableWidth As Single
Dim myTable As Table
Set myTable = ActiveDocument.Tables(1)
With myTable
'Save current setting
TableWidthType = .PreferredWidthType
'Apply width type in absolute, not relative percentage
.PreferredWidthType = wdPreferredWidthPoints
'Get width
If .PreferredWidth = 9999999 Then
TableWidth = CSng(GetSpecialWidth(myTable))
If TableWidth = 0 Then Exit Sub
Else
TableWidth = .PreferredWidth
End If
'Reset width type
.PreferredWidthType = TableWidthType
'Limit to 2 digits after deciaml point
TableWidth = Format(PointsToInches(TableWidth), "#0.00")
MsgBox TableWidth & " inches wide"
End With
End Sub
'_______________________________________
'_______________________________________
Private Function GetSpecialWidth(myTable As Table) As Integer
Dim TableWidth As Integer
Dim iCount As Integer
On Error GoTo DealError
With myTable
For iCount = 1 To .Columns.Count
TableWidth = TableWidth + .Cell(1, iCount).Width
Next iCount
End With
GetSpecialWidth = TableWidth
Exit Function
DealError:
Err.Clear
MsgBox "The table width cannot be calculated, probably because there " _
& "are merged cells in the table.", vbCritical, _
"Cannot compute width"
End Function
'_______________________________________

Signature
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org
JWS315 - 26 Oct 2005 23:02 GMT
Just what I was encoutering - Thanks for the code workaround!!
Thanks - Jerry
> JWS315 was telling us:
> JWS315 nous racontait que :
[quoted text clipped - 77 lines]
> End Function
> '_______________________________________