View Single Post
 
Old 09-21-2018, 01:20 PM
kilroy kilroy is offline Windows 10 Office 2016
Competent Performer
 
Join Date: Sep 2016
Location: Southern Ontario
Posts: 118
kilroy is on a distinguished road
Default

If you don't want to see the columns readjusting then you need to specify the column width. This code is likely nowhere close to as refined as it could be, I'm still a beginner.

Code:
Sub Test()
Dim oDoc As Document
Dim oTbl As Table
text_a = "A text"
text_b = "A longer text to make the column need more width"
text_c = "More text"
Set oDoc = ActiveDocument
Set oTbl = oDoc.Tables.Add(oDoc.Range, 1, 3)
 
 With oTbl
.Columns(1).SetWidth ColumnWidth:=100, _
RulerStyle:=wdAdjustFirstColumn
.Columns(2).SetWidth ColumnWidth:=300, _
RulerStyle:=wdAdjustFirstColumn
.Columns(3).SetWidth ColumnWidth:=100, _
RulerStyle:=wdAdjustFirstColumn
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
.AllowAutoFit = False
 
Selection.WholeStory
With Selection.Borders(wdBorderTop)
.LineStyle = Options.DefaultBorderLineStyle
End With
With Selection.Borders(wdBorderLeft)
.LineStyle = Options.DefaultBorderLineStyle
End With
With Selection.Borders(wdBorderBottom)
.LineStyle = Options.DefaultBorderLineStyle
End With
With Selection.Borders(wdBorderRight)
.LineStyle = Options.DefaultBorderLineStyle
End With
With Selection.Borders(wdBorderHorizontal)
.LineStyle = Options.DefaultBorderLineStyle
End With
With Selection.Borders(wdBorderVertical)
.LineStyle = Options.DefaultBorderLineStyle
End With
.Cell(1, 1).Range.Text = text_a
.Cell(1, 2).Range.Text = text_b
.Cell(1, 3).Range.Text = text_c
End With
With Selection.Tables(1)
For i = 1 To 1
.Rows(i).Select
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.Tables(1).Rows.Alignment = wdAlignRowCenter
Selection.Cells.VerticalAlignment = wdCellAlignVerticalCenter
Next
End With
Selection.WholeStory
With Selection.ParagraphFormat
.SpaceBefore = 1
.SpaceBeforeAuto = False
.SpaceAfter = 1
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
.LineUnitBefore = 0
.LineUnitAfter = 0
End With
Selection.Collapse
End Sub
Reply With Quote