Hello Loungers,
I have rather annoying code problems that I need help. The codes are used to format pre-inserted 4 columns tables to a standard size and format.
Here are the codes:
Sub FormatTable()
If Selection.Information(wdWithInTable) = False Then
MsgBox “Please position the insertion point in a table.”, vbExclamation
Exit Sub
End If
With Selection.Tables(1)
.PreferredWidthType = wdPreferredWidthPoints
.Rows.LeftIndent = CentimetersToPoints(0.8)
.PreferredWidth = CentimetersToPoints(10.5)
.TopPadding = CentimetersToPoints(0)
.BottomPadding = CentimetersToPoints(0)
.LeftPadding = CentimetersToPoints(0)
.RightPadding = CentimetersToPoints(0.1)
.Spacing = 0
.AllowPageBreaks = True
.AllowAutoFit = True
End With
Selection.Tables(1).Select
Selection.Style = ActiveDocument.Styles(“MyTableStyle”)
With Selection.Tables(1)
.Columns(1).Width = CentimetersToPoints(7.5)
.Columns(2).Width = CentimetersToPoints(1.7)
.Columns(3).Width = CentimetersToPoints(0.3) ‘ Error here
.Columns(4).Width = CentimetersToPoints(1)
End With
For j = 2 To 4 Step 2
With Selection.Tables(1).Cell(1, j)
With .Borders(wdBorderBottom)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
End With
End With
Next j
End Sub
The codes always stop at the line I indicated above, giving me error “Run-time Error ‘4608’, Value out of range”. However it occurs randomly, sometimes it happens, and sometimes it doesn’t. But I notice it occurs more often on the page that have more than one tables that need to be formatted with the codes.
Can anyone kindly help please?
Regards
Rid