Problems creating a macro

I’m finding it very difficult to create what should be a fairly simple macro. I need a macro to create a shaded area behind a block of text and then assign a keyboard shortcut.
My workflow (before creating a macro) is to select the paragraph, then go to Format > Paragraph, click on Color, select a color, and click OK.
When I try to record these steps in a macro and then run it, nothing happens.
Am I missing something?

Obviously.
.
Two hints: The macro-recorder is limited and can not record every action.
And as most people here lack clairvoyance it is a good idea to include your macro in your question. (If you include the text in 3 backticks ` at beginning and end it will be more readable.)

Hi Wanderer, thanks for responding. I’m not sure I can do what you ask (I’m not a programmer). All I do is highlight the paragraph that I want to have shaded, then turn on Record Macro, go through the steps shown above, and then Stop Recording. Then I name it and then try to run it.

Please, copy the recorded macro, then paste it here using the tips described by Wanderer.

Is this what you mean?

sub PAAB_yellow
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "NumberingStart"
args1(0).Value = false

dispatcher.executeDispatch(document, ".uno:NumberingStart", "", 0, args1())

rem ----------------------------------------------------------------------
dim args2(0) as new com.sun.star.beans.PropertyValue
args2(0).Name = "NumNewStartAt"
args2(0).Value = 65535

dispatcher.executeDispatch(document, ".uno:NumNewStartAt", "", 0, args2())


end sub

Rather than making a macro, you could create a paragraph style or a character style and assign a keyboard shortcut to it. The paragraph style would create a colored background for the whole paragraph text area. The character style would create a colored background for any block of text including the spaces between words in that block, like using a colored marker in a physical document.

1 Like

Hey TXDon! I think you’ve got the answer. That works a treat!
Thank you.

I spoke too soon! When I do this, I lose any formatting of the text (e.g. bold type reverts to regular).

Here is a possible solution:

Sub PAAB_yellow()
Dim oDoc As Object
Dim dispatcher As Object
Dim args(0) As New com.sun.star.beans.PropertyValue
	
	oDoc = ThisComponent.CurrentController.Frame
	dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
	
	Answer = MsgBox("Are you sure?", MB_YESNO, "Change Background")
	If Answer = IDYES Then
		args(0).Name = "BackgroundColor" : args(0).Value = RGB(255, 255, 0)
		dispatcher.executeDispatch(oDoc, ".uno:BackgroundColor", "", 0, args())
	End If
End Sub

Works great. Thanks FelipeAle!