View Single Post
 
Old 09-21-2018, 03:14 PM
macropod's Avatar
macropod macropod is online now Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by kilroy View Post
If you don't want to see the columns readjusting then you need to specify the column width.
Indeed, but when I wrote the code the OP hadn't said anything about the tables having more than one row; if I'd known that, I'd have written the code differently. For example:
Code:
Sub Test3()
Application.ScreenUpdating = False
Dim Tbl As Table
Const text_a As String = "A text"
Const text_b As String = "A longer text to make the column need more width"
Const text_c As String = "More text"
 
Set Tbl = ActiveDocument.Tables.Add(Range:=Selection.Range, NumRows:=4, NumColumns:=3)
With Tbl
  .AllowAutoFit = False
  .Rows(1).HeadingFormat = True
  .PreferredWidthType = wdPreferredWidthPoints
  .PreferredWidth = CentimetersToPoints(17.5)
  .Columns(1).PreferredWidth = CentimetersToPoints(3.2)
  .Columns(2).PreferredWidth = CentimetersToPoints(13.4)
  .ApplyStyleHeadingRows = True
  .ApplyStyleLastRow = True
  .ApplyStyleFirstColumn = True
  .ApplyStyleLastColumn = True
  .LeftPadding = 0
  .RightPadding = 0
  .Borders.Enable = True
  .Cell(1, 1).Range.Text = text_a
  .Cell(1, 2).Range.Text = text_b
  .Cell(1, 3).Range.Text = text_c
End With
Application.ScreenUpdating = True
End Sub
Note the continued avoidance of Selection...
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote