How to add individual macros to a Menu in Writer?

I have created a new menu in Writer, "BodyCode_PageNames. I have created a number of macros to print out the names of different items from an app, called Body Code. Here is an example of a macro that prints out "HOME > A1 Energy > B1 Allergy or Intolerance

sub HOME_A1_Energy_B1_Allergy_or_Intolerance
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 = “Bold”
args1(0).Value = true

dispatcher.executeDispatch(document, “.uno:Bold”, “”, 0, args1())

rem ----------------------------------------------------------------------
dim args2(2) as new com.sun.star.beans.PropertyValue
args2(0).Name = “FontHeight.Height”
args2(0).Value = 14
args2(1).Name = “FontHeight.Prop”
args2(1).Value = 100
args2(2).Name = “FontHeight.Diff”
args2(2).Value = 0

dispatcher.executeDispatch(document, “.uno:FontHeight”, “”, 0, args2())

rem ----------------------------------------------------------------------
dim args3(0) as new com.sun.star.beans.PropertyValue
args3(0).Name = “Color”
args3(0).Value = 8388736

dispatcher.executeDispatch(document, “.uno:Color”, “”, 0, args3())

rem ----------------------------------------------------------------------
dim args4(0) as new com.sun.star.beans.PropertyValue
args4(0).Name = “Text”
args4(0).Value = "HOME > A1 Energy > B1 Allergy or Intolerance > "

dispatcher.executeDispatch(document, “.uno:InsertText”, “”, 0, args4())

rem ----------------------------------------------------------------------
dim args5(0) as new com.sun.star.beans.PropertyValue
args5(0).Name = “Bold”
args5(0).Value = false

dispatcher.executeDispatch(document, “.uno:Bold”, “”, 0, args5())

rem ----------------------------------------------------------------------
dim args6(0) as new com.sun.star.beans.PropertyValue
args6(0).Name = “Color”
args6(0).Value = 0

dispatcher.executeDispatch(document, “.uno:Color”, “”, 0, args6())

rem ----------------------------------------------------------------------
dim args7(2) as new com.sun.star.beans.PropertyValue
args7(0).Name = “FontHeight.Height”
args7(0).Value = 12
args7(1).Name = “FontHeight.Prop”
args7(1).Value = 100
args7(2).Name = “FontHeight.Diff”
args7(2).Value = 0

dispatcher.executeDispatch(document, “.uno:FontHeight”, “”, 0, args7())

end sub

I have already copy/pasted this code above, and then just changed the text field to create 20 or so macros like this. But eventually I will create a hundred or more of these macros to print out the names of the items in the app.

I have added the “Run Macro” command to this menu, and this is a start, but it is too time consuming to open it, then click on the right Module and then the macro that I want. I could, of course, set up key commands for each one, but this would entail setting up some kind of system, like CTR+Alt+A for the first one, and then on to B, and so on. But I would eventually run out of available key strokes, and then how to quickly remember which for which.

What I want to do is add this macro, and like I say, eventually a hundred or more like it, to the new Menu item I created, and click on it to run it. Is this possible, and if so, can someone please give me instructions on how to do this?

Thanks so much for you help.

Maybe Customising menus can help you.

1 Like

Thanks for the link David. I have gone over this information, but it does not tell me how to directly access a link to a macro name and then allow me load that macro name in the menu I created, and run the macro when I click on it.

Have a great day.

Go to Tools | Customise and select Menus tab.


Choose category Macros to see all macros. Collapse the Application Macros tree to see your macros. Use the right menu Scope etc to make the various selections. Some options will not be available unless there is an open document.

Wowser! That’s the ticket robleyd, this is just what I was looking to accomplish. I would never have figured this out. This will save me tons of time when I am helping people decode their health issues.

Thanks so much.

Have a great day.