Hello,
How to remove borders on cells with a macro (Basic) in Calc, and without using dispatch commands. Thanks in advance!
If you make a cell style without borders, then only apply it.
Sub change_borders()
selection = ThisComponent.CurrentSelection
selection.CellStyle = "clean"
End Sub
but, of course, if you like pain.
Dim border_line As New com.sun.star.table.BorderLine
selection = ThisComponent.CurrentSelection
With border_line
.Color = 0
.InnerLineWidth = 0
.OuterLineWidth = 0
.LineDistance = 0
End With
With selection
.TopBorder = border_line
.BottomBorder = border_line
.LeftBorder = border_line
.RightBorder = border_line
End With
Look atached file. The same code works in upper example, but do not remuve all borders in bottom example. Why?
RemoveBorders.ods (24.6 KB)
Please, use code like in the example.
Yes, your example works. I just want to escape the selection in your code to avoid jumping the image if the selected range is not visible on the screen.
Well, rewrite @elmau’s code as
Sub delBorderLine(selection As Variant)
Dim border_line As New com.sun.star.table.BorderLine
With border_line
.Color = 0
.InnerLineWidth = 0
.OuterLineWidth = 0
.LineDistance = 0
End With
With selection
.TopBorder = border_line
.BottomBorder = border_line
.LeftBorder = border_line
.RightBorder = border_line
End With
End Sub
and then your two long procedures will turn into
Sub removeBorderLine
delBorderLine(ThisComponent.Sheets.getByName( "Sheet1" ).getCellRangeByNAme("B2:D13"))
End Sub
Sub removeBorderLine2
delBorderLine(ThisComponent.Sheets.getByName( "Sheet1" ).getCellRangeByNAme("B30:O58"))
End Sub
1 Like
Thanks JohnSUN!