PDA

View Full Version : [SOLVED:] Table row lines without column lines



StarPig
01-09-2019, 10:42 AM
Good evening

I have the following code, from VBA Express you made, but I am unable to remove the vertical borders? I only wish to have horizontal borders - on rows / cells that are selected.
Can you assist me please? Thank you.


Sub TableLines()
Dim tbl As Table
Dim Icol As Integer
Dim Irow As Integer
On Error GoTo err
Set tbl = ActiveWindow.Selection.ShapeRange(1).Table
'exit if no selected table
If err.Number <> 0 Then Exit Sub
For Irow = 1 To tbl.Rows.Count
For Icol = 1 To tbl.Columns.Count
If tbl.Cell(Irow, Icol).Selected Then
'hide existing borders
For i = 1 To 6
tbl.Cell(Irow, Icol).Borders(i).visible = msoFalse
Next i
For i = 1 To 4
With tbl.Cell(Irow, Icol).Borders(i)
.visible = msoTrue
.ForeColor.RGB = RGB(180, 180, 180)
.Weight = 1
End With
Next i
End If
Next Icol
Next Irow
Exit Sub ' usual exit
err: 'error
MsgBox "Please select table rows / cells and try again"
End Sub

John Wilson
01-09-2019, 12:06 PM
Unfortunately this is a long standing bug in MSFT's code.

You could try this but it may not work as expected.


Sub TableLines()
Dim tbl As Table
Dim Icol As Integer
Dim Irow As Integer
Dim i As Integer
On Error GoTo err
Set tbl = ActiveWindow.Selection.ShapeRange(1).Table
' hide selected borders
Call CommandBars.ExecuteMso("BorderNone")
DoEvents
'exit if no selected table
If err.Number <> 0 Then Exit Sub
For Irow = 1 To tbl.Rows.Count
For Icol = 1 To tbl.Columns.Count
If tbl.Cell(Irow, Icol).Selected Then
For i = 1 To 3 Step 2
With tbl.Cell(Irow, Icol).Borders(i)
.Visible = msoTrue
.ForeColor.RGB = RGB(180, 180, 180)
.Weight = 1
End With
Next i
End If
Next Icol
Next Irow
Exit Sub ' usual exit
err: 'error
MsgBox "Please select table rows / cells and try again"
End Sub