Pages

Friday, July 3, 2026

Circumvent LibreOffice Macros with Templates

Instead of writing LibreOffice macros to change a default behavior, consider customizing the default template.

Creating macros is fun for me. But I agree, automating LibreOffice with macros is daunting, and the recorder is a poor way to begin writing code.1

Recently I wanted to change the default anchor position of an image. When I insert an image by pasting, I want its anchor is to be "As Character" as opposed to paragraph, which was the current default.

I tried to record the process:

  • Paste
  • F4 (properties)
  • As Character
  • OK
  • Press Enter

The recorder captured the Paste and Enter keys well. Unfortunately, it choked on the macro's primary element -- applying the As Character property.

But then I wondered, "Can the default anchor position be set to "As Character" in Options?" "No, it cannot," I answered.2 "But you can change it in the default template. Here's how:"

  • Start LibreOffice Writer. This should present a new, blank document. But if it doesn't, press Ctrl+N.
  • Press Alt+2 to open the Styles sidebar.
  • Click the Frame Styles icon. (Please see Figure 1, Frame Styles below.)
  • An image of the sidebar in which Styles is selected.  The Frame Styles button has been clicked, and the mouse pointer hovers over on the icon so that the "Frame Styles" tooltip shows.
    Figure 1 -- Frame Styles

  • Right click on Graphics and choose Edit Style... as shown in Figure 2.
  • Image shows how the interface appears after right-clicking the Graphics style element.  The context menu shows three choices: New, Edit Style and Hide
    Figure 2 -- Edit Graphics Style

  • Choose "Type" on the left. Its icon looks an anchor.
  • Under Anchor, click the radio button next to As character.
  • Review the other settings and change whatever other defaults that don't make sense to you. I recommend clicking the checkbox to lock Height to Width (aka Aspect Ratio in other applications). Mine was unchecked, and I always found myself clicking it.
  • Choose File | Templates | Save as Template as shown in Figure 3. Note this is different from doing File | Save As and then choosing the OTT file type. And yes, you will be saving the image in the template, but it can be removed later.
  • The image shows the three options after clicking File and then Templates from the menu
    Figure 3 -- Save as Template Menu Selection

  • Enter a name for the template. I entered DEMO for this How-To, but I tend to give my templates more description names that include the paper size, such as "4 x 6 index card" or "5 x 7 greeting card LS."
  • Choose a category to enable the Save button.
  • Click the checkbox labeled "Set as default template" to ensure that every subsequent new Writer document will be derived from the new template.
  • Note that these three choices (Name, Category, Default) can be changed in the Template Manager (Ctrl+Shift+N). The dialog should look similar to the one in Figure 4, below.

  • The image is a screenshot of the Save Template Dialog box, where the template name is "DEMO," the category "My Templates" is selected and the checkbox indicates that it should be set as the default template
    Figure 4 -- The Save Template Dialog Box


  • Press Ctrl+N to create a new document. Paste an image into it to test the new template. Hopefully3 you'll get the desired result.

1 "When the macro recorder is not able to solve a specific problem, the usual solution is to write code using the OpenOffice.org objects. Unfortunately, there is a steep learning curve for the OOo objects."
2 Sometimes I gain insight into a problem by splitting myself into student and teacher.
3 I write "Hopefully" because as I repeated these steps to test them, I managed to obliterate my own default template. And I couldn't seem to fix it without restarting Writer.

No comments:

Post a Comment

Thank you for taking time to comment. Please note that comments may be deleted if they:

* Contain link(s) to a domain outside USA or Canada or to a commercial enterprise.
* Include non-English words or characters.
* Are irrelevant to the subject matter of the post.

For posts older than 14 days, comments are moderated and require approval.