How do I add a macro to a template?

I want to add a macro (and a toolbar icon) to a template. How do I best do this? It is only for use in one particular template.

Hello,

Step 1 Define the macro

  • open an empty Writer document
  • Tools -> Macros -> Organize Macros > Basic...
  • Select Untitled 1 in pane titled Macro from
  • Click button New
  • Provide a Name: of your Module (or accept Module1)
  • Click OK
  • Add your macro code to the dialog in the right pane
  • Close macro editor using File -> Close

Step 2 Add the toolbar icon

  • Tools -> Customize... -> Tab: Toolbar
  • Select Untitled 1 in drop down Scope
  • Select the toolbar, where you want you icon to appear in drop down Target (you may want to create a new target, e.g called Invoice, by clicking the button to the right of the drop down and using Add..
  • In drop down Category select Macros
  • Select the macro created in Step 1 from entry Untitled 1 (expand the entry by clicking the arrow)
  • Click the black right arrow to the right
  • Select the Macro Name in pane named Assigned Command
  • Click button Modify -> Change Icon... and define you button to be added (may be you want to import your own icon)
  • Click OK

Step 3 Save as Template

  • File → Template → Save as Template …`

  • Provide a Template Name (e.g. Invoice)

  • Select a Template Category (e.g. My Templates)

  • Click button Save

  • Close the document Untitled 1 (no need to save)

Hope that helps