How do I make a button to apply a Table AutoFormat?

I have a document with a large number of tables in it, and I need to update the formatting on them all.

I have a Table AutoFormat already set up, with the settings I want. However, for each table I come across, I need to manually go to Table => AutoFormat => (Select Style) => OK.

Is there an easy way to make applying the style a one-click operation? I recorded a Macro of applying the style, but that doesn’t seem to work.

When your searches on Google with LibreOffice don’t give you satisfactory results, search for OpenOffice, it reveals a whole new level of ancient treasure.

I believe you searched for this topic:

https://forum.openoffice.org/en/forum/viewtopic.php?t=41557

I copy over the final answer by Tim Grantham in case that webpage is unavailable:

    // Get the TextTablesSupplier interface of the document
    XTextTablesSupplier xTableSupplier = (XTextTablesSupplier) UnoRuntime.queryInterface(XTextTablesSupplier.class, xDoc);

        // Get an XIndexAccess of TextTables
        XIndexAccess xTables = (XIndexAccess)UnoRuntime.queryInterface(
            XIndexAccess.class, xTableSupplier.getTextTables());

    int tablecount = xTables.getCount();

    for (int i=0; i < tablecount; i++) {

        XAutoFormattable xAutoFormattable = ( XAutoFormattable ) UnoRuntime.queryInterface (
            XAutoFormattable.class, xTables.getByIndex( i ) );

        xAutoFormattable.autoFormat("simpletable_header");

    }