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
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