3.14159265358979323846
Yes, you must completely rewrite the MS VBA code based on the LO API and one of the supported programming language of the LibreOffice. The LibreOffice supports more than one programming languages. The most similar to the Basic of the VBA is the StarBasic (or it should be named simple “Basic” - the name “StarBasic” comes from the StarOffice era.)
But, there is an option for more compatibility with the VBA in the StarBasic. Try it: your VBA code maybe can run in LibreOffice by usage of this Option:
https://help.libreoffice.org/latest/en-US/text/sbasic/shared/03103350.html
  →
The o.p. can try the Option VBAsupport - without rewriting the macro. I (we) can not try the code without sample documents.
this can be done with altsearch extension with the \R trick on regular expression Replace All,
e.g.
see embedded help for details on redirection.
the sorting by paragraph-size into new document with python:
from com.sun.star.text.ControlCharacter import PARAGRAPH_BREAK as BREAK
def new_doc(which):
desktop = XSCRIPTCONTEXT.getDesktop()
return desktop.loadComponentFromURL(f"private:factory/s{which}",
"_blank",
0,
(),)
def clone_para(cursor, paragraph):
for portion in paragraph:
cursor.String = portion.String
names = [ prop.Name for prop in portion.PropertySetInfo.getProperties() ]
values = [ portion.getPropertyValue( name ) for name in names]
for name, value in zip(names, values):
try:
setattr(cursor, name, value)
except:
pass
cursor.gotoEnd(False)
def main(*_):
doc = XSCRIPTCONTEXT.getDocument()
paras = sorted(doc.Text, key=lambda para: len(para.String), reverse=True)
_new = new_doc('writer')
_new.lockControllers()
text = _new.Text
tc = text.createTextCursor()
for para in paras:
clone_para(tc, para)
text.insertControlCharacter(tc.End, BREAK, False)
_new.unlockControllers()
Sorry I’m new, are python macros different from regular ones? If so I’m willing to learn, I was just curious if it was possible as regular macros like it works in MS Word like I’m more used to. Thank you for any help
Yes, as you use another programming language, and python brings its own standard library (some items may be missing in LibreOffice).
For example in code above you may notice the advanced possibilities to iterate over data-structures:
for name, value in zip(names, values):
try:
.
“No” would be also right, as you use the same API. Simple procedures, where you only pass some parameters to an API-call will be quite similiar in any language.
…then you should use the extension apso.oxt from here to manage and organizing your python-scripts.
And have tried the suggested Option for your code in an .odt document?
Can you upload some small size sample documents here?
No not yet, why sample documents?
Seems your assumptions about this forum are basically wrong.
- The helpers are users like you. You didn’t hire them.
- If you tell us you got something that worked for you in a different forum, you should, of course, post a link to the respective thread.
- In no case you should expect helpers to do two time-consuming things instead of one.
(1) Understand the given code deeply, and find out what you precisely wanted to achieve.
(2) Write new code for a different software following very different concepts using the native means (LO Basic, LO API) of this software. - You ask for help by people you estimate yourself to be superior to you in understanding the field. You should then also accept advice or give reasonable arguments for waht reasons this isn’t possible.
- This lacks very relevant information:
What to do with headings which mostly are short paragraphs, often using a special format?
What to do with TextTables contained in the body text?
What to do with embedded objects (shapes, TextFrames, OLE,...)
Shall I write this all again for the next newcomer to the forum?
This is getting really annoying. Accept wishes for an example and other advice, or leave the forum because it can’t be useful under these conditions.
Users trying to help have yet posted >10 replies. Do you think they did this in a minute?
See also:
disask_128922_CollectMarkedParagraphs.odt (22.4 KB)
Like words like “like”.

