troubleshooting Question

problem with last line of a table in Microsoft Word

Avatar of thenelson
thenelson asked on
VBAMicrosoft Word* tables
7 Comments1 Solution275 ViewsLast Modified:
Occasionally, the bottom gridline of a table in Microsoft Word disappears (see image below). bottom gridline missingI 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 Integer

intColumnIndex = Selection.Cells(1).ColumnIndex
Selection.GoTo wdGoToBookmark, , , "VitalSigns"
Selection.MoveDown wdLine, 1
Selection.HomeKey wdLine
Selection.MoveRight wdWord, 5, wdExtend
If IsDate(Selection.Range.Text) Then
    datePreviousVisit = InputBox("Enter Fill date:", , CDate(Selection.Range.Text))
    datePreviousVisit = InputBox("Enter Fill date:")
End If
If 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 If
Next cellLoop
ActiveDocument.Tables(3).Cell(1, intColumnIndex).Select
End 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?

ITSysTechSenior Systems Administrator

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros