LibreOffice Writer Macro to find a specific text and give page break before that text

We used to download a file everyday. Some people use Libreoffice version 4.x to 6.x some people use Ubuntu 14.04 to 20.04. We have to detect a phrase "In the court of followed by random words then random lines then a table. Everyday we have to give manual page break if the phrase In the court of followed by random words then 4-5 lines and then a table dont used to be on same page. I want a libreoffice writer macro that will search for a specific text thereafter 4-5 lines and table. If the specific text, then the lines and table breaks across pages there should be a page break before the specific text.

Edit your question (don’t answer with a comment) to better explain your purpose and give an example. The fact that you want to detect something and modify at another location makes the problem difficult.

Wouldn’t it be simpler to configure your table beforehand.

I don’t see clearly where the page break is added. So, describe the sequence of “objects” in your document. Also tell us how you format it (styles vs. direct format). Direct format will make things complicated.

Don’t forget to mention OS name, LO version and your preferred save format (stability of formatting is guaranteed only with .odt).