keyNodeColor.setPropertyValue("Color", rgb(R,G,B)) no longer works

We have been using a macro to assign the document background color since version 24.8.2 or even earlier. The macro has stopped working with the latest upgrade:

Version: 25.2.0.3 (X86_64) / LibreOffice Community
Build ID: e1cf4a87eb02d755bce1a01209907ea5ddc8f069
CPU threads: 4; OS: Windows 11 X86_64 (10.0 build 22000); UI render: Skia/Raster; VCL: win
Locale: en-CA (en_CA); UI: en-US
Calc: CL threaded

This is a snippet of the code with the last line causing the macro to fail:

	R = Doc.Sheets.getByName("Setup").getCellRangeByName("DocBgRed").Value
	G = Doc.Sheets.getByName("Setup").getCellRangeByName("DocBgGreen").Value
	B = Doc.Sheets.getByName("Setup").getCellRangeByName("DocBgBlue").Value
	keyNodeColor.setPropertyValue("Color", rgb(R,G,B))

This is the error message:

BASIC runtime error.
An exception occurred
Type: com.sun.star.beans.UnknownPropertyException
Message: Color.

Can someone please point me in the right direction.

Thank you

Please think before sending snippets, how people who want to help you are going to know what keyNodeColor is, and how they run your snippet to see the problem locally, to debug and change code?

1 Like

Please upload the full macro code and an ODF type sample file here.

You can use the MRI or the XrayTool to list the existing properties, methods (and others) of the programming Objects.

I’m sorry, here is the full Sub

Sub ChangeDocBgColor

'You change the colour by picking a colour from the list, or by entering an RGB value.

GlobalScope.BasicLibraries.LoadLibrary("Tools")

Dim keyNode 							As Object ' com.sun.star.configuration.Configuration(Update)Access '
Dim Setup									As Object
Dim curScheme 						As String
Dim NodeName 						As String
Dim keyNodeColor 					As Object
Dim MsgStr								As String
Dim Colours								As Integer : Colours =13
Dim Colour(Colours)				As Long
Dim ColourName(Colours)		As String
Dim I 											As Integer
Dim R,G,B									As Integer
Dim Value 									As String

On Local Error GoTo ErrorHandler
	
Doc				= ThisComponent
Setup			= Doc.Sheets.getByName("Setup")
	
Colour(1)		= 16777215	: ColourName(1) = "White"
Colour(2)		= 8421504 	: ColourName(2) = "Grey"
Colour(3)		= 13882323	: ColourName(3) = "LightGrey"
Colour(4)		= 9868950		: ColourName(4) = "LightGrey2"
Colour(5)		= 16711680	: ColourName(5) = "Red"
Colour(6)		= 65280			: ColourName(6) = "Green"
Colour(7)		= 16776960	: ColourName(7) = "Yellow"
Colour(8)		= 255				: ColourName(8) = "Blue"
Colour(9)		= 16711935	: ColourName(9) = "Purple"
Colour(10)		= 8388736		: ColourName(10) = "Purple2"
Colour(11)		= 65535			: ColourName(11) = "AquA"
Colour(12)		= 0					: ColourName(12)	 = "Black"


' Get current color scheme
keyNode = Tools.Misc.GetRegistryKeyContent("org.openoffice.Office.UI/ColorScheme", False)
curScheme = keyNode.CurrentColorScheme
' Get the scheme node
nodeName = "org.openoffice.Office.UI/ColorScheme/ColorSchemes/" & curScheme & "/DocColor"
' Set the root path for our configuration access
keyNodeColor = Tools.Misc.GetRegistryKeyContent(nodeName, True)

MsgStr =  "Enter the number of the Document Background Colour you wish. "

I = 1
Do While I < Colours
	MsgStr = MsgStr & CHR(10) & " "&  I & " " &ColourName(I) 
	I = I + 1
Loop
MsgStr = MsgStr & Chr(10) & " " & Colours & " Use the saved RGB values on the Setup Sheet"

' We get the entered value.
Value = InputBox(MsgStr, "Documment Background Colour","")
 If Value = "" Then
 	Exit Sub
 End If

If Value = Colours  Then	' We get the colours f rom the Setup Sheet.
	R = Doc.Sheets.getByName("Setup").getCellRangeByName("DocBgRed").Value
	G = Doc.Sheets.getByName("Setup").getCellRangeByName("DocBgGreen").Value
	B = Doc.Sheets.getByName("Setup").getCellRangeByName("DocBgBlue").Value
	keyNodeColor.setPropertyValue("Color", rgb(R,G,B))
	keyNodeColor.commitChanges()
	Exit Sub
End If

' It must be one of the standard colours in the list. We use the appropriate decimal value for that colour.
If Int(Value) < 1 or Int(Value) > Colours -1 Then
   MsgBox "Please enter a number between 1 and " & Colours -1 & "." & " " & Value
   Exit Sub
End If
' Replace Colour values below
keyNodeColor.setPropertyValue("Color",Colour(Value))
keyNodeColor.commitChanges()

Exit Sub

ErrorHandler:
MsgBox "Something is wrong in the macro. Are your values incorrect?"

End Sub ’ ChangeDocBgColor

It works for my in MY sample file in my LO 7.5.8. and LO 24.8.2.4 portable versions:
DocBgColorMacro.ods (12.2 KB)

Regression in 25.2 after commit eaa5a4de85c7b7a8b606614a1dca6cee6badfb4a. You may want to file a bug report.