The macro below is intended to put some text into cells, change backcolor and borders of these cells. It works properly when macro creates a new file and modifies its cells. But when the macro loads an existing file and modifies it, changing the text into cells works properly, while changing backgroundcolor and borders fails. Why? Windows 10, LO 6.3.6.2.
Sub Borders
Dim oSheets
Dim oSheet
Dim i As Integer
Dim oDoc
Dim noArgs()
Dim URL As String
REM ------------------------------------
’ create new file
’ URL = “private:factory/scalc”
’ oDoc = StarDesktop.LoadComponentFromUrl(URL, “_default”, 0, noArgs())
'------------------------------------
’ OR
'------------------------------------
’ change existing file
Url = “file:///C:\ddd\File1.ods”
oDoc = StarDesktop.loadComponentFromURL(Url, “_default”, 0, noArgs())
'------------------------------------
oSheets = oDoc.Sheets
oSheet = oSheets.GetByName(“Sheet1”)
dim oBorder as object, oCell as object
oBorder = CreateUnoStruct(“com.sun.star.table.BorderLine”)
oBorder.Color = RGB(0, 0, 0)
oBorder.OuterLineWidth = 20
oSheet.GetCellByPosition(1, 1).string = “Valeur Total”
oSheet.GetCellByPosition(4, 1).string = Format(35.36, “0.00”)
oSheet.GetCellByPosition(4, 1).CellBackColor = RGB(0,0,100)
oSheet.GetCellByPosition(5, 1).string = “Euro”
oSheet.GetCellByPosition(5, 1).CellBackColor = RGB(100,0,0)
for i = 0 to 6
oCell = oSheet.getCellByPosition(i, 1)
oCell.TopBorder = oBorder
oCell.BottomBorder = oBorder
next i
msgbox “STOP”
End Sub