problem with last line of a table in Microsoft Word
Occasionally, the bottom gridline of a table in Microsoft Word disappears (see image below). I have tried many ways to correct this: reformat the table, add a line, etc but nothing works to get the gridline back.
When I use the following code:
Sub GetAvg()Dim cellLoop As Cell, CellContents, datePreviousVisit, intColumnIndex As IntegerintColumnIndex = Selection.Cells(1).ColumnIndexSelection.GoTo wdGoToBookmark, , , "VitalSigns"Selection.MoveDown wdLine, 1Selection.HomeKey wdLineSelection.MoveRight wdWord, 5, wdExtendIf IsDate(Selection.Range.Text) Then datePreviousVisit = InputBox("Enter Fill date:", , CDate(Selection.Range.Text))Else datePreviousVisit = InputBox("Enter Fill date:")End IfIf Len(datePreviousVisit & "") = 0 Then Exit Sub Else datePreviousVisit = CDate(datePreviousVisit)'Debug.Print Format(datePreviousVisit, "mmm dd, yyyy")For Each cellLoop In ActiveDocument.Tables(3).Columns(intColumnIndex).Cells CellContents = Split(Left(cellLoop.Range.Text, Len(cellLoop.Range.Text) - 2), ",") If UBound(CellContents) = 1 Then cellLoop.Range.Text = Trim(CellContents(0)) If CellContents(1) = "" Then CellContents(1) = 0 cellLoop.Range.Text = Trim(CellContents(0)) & ", " & Trim(CellContents(1)) & ", " & Trim(Round((cellLoop.Range.Calculate - CellContents(1)) / DateDiff("d", datePreviousVisit, ActiveDocument.Bookmarks("DOS").Range.Text), 1)) End IfNext cellLoopActiveDocument.Tables(3).Cell(1, intColumnIndex).SelectEnd Sub
with the missing gridline, I get this error message: "run time error 5992; Cannot access individual columns in this collection because the table has mixed cell widths."
Is there a way to get the gridline back or a way to change the code so it runs with the missing gridline?
Thanks
VBAMicrosoft Word* tables
Last Comment
ITSysTech
8/22/2022 - Mon
ITSysTech
If you click on an effected cell what does "Text Direction" show?
ITSysTech
Also, try changing the alignment to "Top".
thenelson
ASKER
Text direction is normal:
Alignment is already set to top: alignment.png