I wanted Writer to print a suit symbol for clubs, hearts, diamonds and spades to I can write a book on bridge with red suit symbols for diamonds and hearts. The Macro will only run as an unsigned macro if I set security to low.
Tools/Options/LibraOffice/Scurity then click the Macro Security button and choose low for now. You will need to sign the macros if you want them to run otherwise.
I posted the following code in a module called Cards. I then set up short cuts on Alt C Alt D, Alt H and Alt S for each of the suit symbols. To do this choose Tools/Customise and choose Keyboard Tab.
Then in the category box scroll down to LibraOffice Macros and drill down to choose you macro so that it shows in the function box on the right. Then choose your shortcut fro the top list and click the modify button so that the shortcut appears in the Keys list at the bottom right. Click OK to save.
One drawback is that it does not find out the font color before changing to red so when it changes back it will always choose black. If you want to write in a different colour you would need to change this macro and unfortunately I don’t know how.
sub Club
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args3(1) as new com.sun.star.beans.PropertyValue
args3(0).Name = "Color"
args3(0).Value = 0
dispatcher.executeDispatch(document, ".uno:Color", "", 0, args3())
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Text"
args1(0).Value = "♣"
dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args1())
end sub
sub Diamond
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(1) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Color"
args1(0).Value = 15797516
dispatcher.executeDispatch(document, ".uno:Color", "", 0, args1())
dim args2(1) as new com.sun.star.beans.PropertyValue
args2(0).Name = "Text"
args2(0).Value = "♦"
dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args2())
dim args3(1) as new com.sun.star.beans.PropertyValue
args3(0).Name = "Color"
args3(0).Value = 0
dispatcher.executeDispatch(document, ".uno:Color", "", 0, args3())
end sub
sub Heart
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(1) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Color"
args1(0).Value = 15797516
dispatcher.executeDispatch(document, ".uno:Color", "", 0, args1())
dim args2(1) as new com.sun.star.beans.PropertyValue
args2(0).Name = "Text"
args2(0).Value = "♥"
dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args2())
dim args3(1) as new com.sun.star.beans.PropertyValue
args3(0).Name = "Color"
args3(0).Value = 0
dispatcher.executeDispatch(document, ".uno:Color", "", 0, args3())
end sub
sub Spade
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args3(1) as new com.sun.star.beans.PropertyValue
args3(0).Name = "Color"
args3(0).Value = 0
dispatcher.executeDispatch(document, ".uno:Color", "", 0, args3())
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Text"
args1(0).Value = "♠"
dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args1())
end sub