How do I make a "X" in cell via macro?

I have this macro in order to make a table:

Sub MakeATable
Dim oDoc, oController as Object
Dim oSheet, oCurrentSelection, oDocument as Object
Dim sName as String
Dim oSel as Object
Dim oFunction as Object
Dim sMyString as String
Dim oCell, oAnnotation as Object
Dim sGetComment as String
Dim sSheetName as String
Dim pVertW, pHoriW, pOuterW, pInnerW, pLiDist as Integer
Dim pRgb as Long
Dim lRow as Long
pVertW  = 20
pHoriW  = 20
pOuterW = 40
pInnerW = 20
pLiDist = 40
pRgb    = RGB(100, 80, 255)
Dim borderLine As New
Dim tb2        As New
Dim rng, oLastCol, oCursor as Object
Dim oRow as Object

oSheet = ThisComponent.Sheets.getByName("Gratuita")
oLastCol = oSheet.getCellRangeByName("E1") ' Coluna E
oCursor = oSheet.createCursorByRange(oLastCol)
lRow = oCursor.RangeAddress.EndRow
rng = oSheet.getCellRangeByName("A11:H" & lRow)
rng.CharHeight = 11
rng.CharFontName = "Calibri"
oRow = rng.getRows()
oRow.Height = 450
oSheet.Rows.removeByIndex(lRow+2, 65500)
REM SheetCellRanges selectiopns make no sense, object (Shape e.g.) selections even less.
borderLine.Color = RGB(0, 0, 0)
'  borderLine.LineStyle = 1 ' apaga a borda da tabela
borderLine.LineStyle = 0 
borderLine.LineWidth = pVertW
tb2.VerticalLine = borderLine
tb2.IsVerticalLineValid = True
borderLine.LineWidth = pHoriW
tb2.HorizontalLine = borderLine
tb2.IsHorizontalLineValid = True
' borderLine.LineStyle = 1 ' apaga o interior da tabela
borderLine.LineStyle = 0
borderLine.LineDistance = pLiDist
REM With double borderlines having set different outer an inner widths.
REM there is a bug for many years now. It was never resolved, and will most likely neverba.
REM Too much code meanwhile relying on the bug - like this Sub!
REM 'Outer' is wrongly interptreted as 'Top or Right', 'Inner' as 'Left or Bottom. 
REM The problem is basically the same with LineStyles 4 through 9 which create predefined double lines.
borderLine.OuterLineWidth = pOuterW
borderLine.InnerLineWidth = pInnerW
tb2.TopLine = borderLine
tb2.IsTopLineValid = True
tb2.RightLine = borderLine
tb2.IsRightLineValid = True
borderLine.OuterLineWidth = pInnerW  REM A little bit counterintuitive.
borderLine.InnerLineWidth = pOuterW  REM A little bit counterintuitive.
tb2.LeftLine = borderLine
tb2.IsLeftLineValid = True
tb2.BottomLine = borderLine
tb2.IsBottomLineValid = True
rng.TableBorder2 = tb2
Sub End

I want to make a “X” (diagonal lines) in cell.
Like this

what variables do I use in that macro structure?

Without all that Basic, you could apply styles via double-click, via conditional formatting, via shortcut or oCell.CellStyle = “Crossed Border”

1 Like

There are the properties for diagonal lines for the variable rng, use xray rng or mri rng.


Thanks a lot.
I use the following codes:
borderLine.LineStyle = 0
pVertW = 20 ’ 0 in order to erase the diagonal lines
borderLine.LineWidth = pVertW
rng.DiagonalBLTR2 = borderLine
rng.DiagonalTLBR2 = borderLine