LibreOfficer Writer Macro to search all occurrences of text and place a text in the next line right aligned

I am using Ubuntu 22.04 and LibreOffice 7.5.5.2. I want to create a macro that will search for text “: Proceeding is closed” and placed “(Any Name)” in the next line and that too right aligned.

Thanks in advance.

If you want to do something… you should do something

I used to take help of ask libreoffice for the task I don’t know. The answer to this question will not solve my entire problem. I used to apply my mind. This question is just part of what I want to do. It is just 10% of my problem.

@AniruddhaMohod but your ask is in essence the same issue repeatedly :frowning: → find something with SearchDescriptor, move cursor, and insert some data.
If your previous posts are only 10% of your precondition, and we will write all macros with the combinations for oDesc, oVCur and Paste, but you will not understand to these simple macros, then I afraid there will be big chaos in your system → and then will you ask the great solution for some big muddle? Unfortunately if you don’t want to learn some simple and continuosly the same macros that you want, but you want to have big macro system, I think I cannot help you, because I suppose there will be big chaos in your system and I don’t want to cooperate on some “but-I-thought-it-will-be-easy” muddle :slight_smile:

1 Like

Your solutions proved extremely helpful for me. Presently, the below macro proves helpful for me. But if the name is bigger then it goes to next line. That’s why I feel it should be right aligned.

dim oDoc17 as object, oDesc17 as object
oDoc17=ThisComponent
oDesc17=oDoc17.createReplaceDescriptor
with oDesc17
.SearchString=": Proceeding is closed"
.SearchRegularExpression=true 'by regexp
.ReplaceString= “&\n\t\t\t\t\t” + sText
end with
oDoc17.replaceAll(oDesc17)

Just inserting a lot of tabs to get the text as far to the right as you can is very bad style, both when you do it manually and in a macro. Enter one tab stop and make it right aligned. If all text where you do that is the same paragraph style, all you have to do for that is to modify the tabs settings in the Default paragraph style. Define one tab stop and set it to right aligned.

warning condescenscion ahead! :smirk: When I started with word processors, I did very much the same things as you do now. Then I realized that the software was a productivity tool, developed by smart people with the intent to help you do things as efficiently as possible. I should just be lazy and search the documentation for a fast way to do what I was doing in a very roundabout way. It helped every single time.

Learn to get the most out of working with styles, learn to use tabs efficiently if you have to use them at all. Writer is not a mechanical typewriter, get the most out of that. For that, you have to think more methodical, more structured, and that will help you get on with macro programming as well.

To change a paragraph style just to be able to insert something right aligned into an extra line (hard break) should be avoided. In fact I would suggest to make such insertions into extra paragraphs whit their own (aligned) paragraph style.
Of course this will change the appearance concerning text-flow and page-wrapping, but that’s unavoidable anyway. On the other hand the inserted paragraphs can easily be found by F&R or based on user code, and may then even be removed if no longer needed.
See attached:
disask94620demoComplicatedReplacemenmtAndAlignmentByStandar5dTools.odt (154.4 KB)

Not knowing what "Any Name" is meant to mean here, I tried a demo how to do it based on ordinary standard tools and an extra paragraph style.
The first step requires unavoidably the usage of a RegularExpression, and a related Replacement. Your "Any Name" needs to replace exactly the three characters "vel" there. Special characters of RegEx must not occur.

Problem is the more \t in String. And it seems it is a time to start to use the extension MRI or XRay :slight_smile: → for example mri oVCur or xray oVCur to show the properties of some variable.
For paragraph align is the property ParaAdjust → for example oVCur.ParaAdjust=1 to set align to right.
Or you can set your own Paragraph Style and in macro oVCur.ParaStyleName="MyPara"

I always use tab stop. But here in this case the macro will be going to use by hundred and thousands of people and they even don’t know \t or use of tab stop.

Your previous solutions proved extremely useful for me. By 10 percent I mean, I used to do 90 percent coding and for 10 percent difficulties I used to ask Asklibreoffice. It is true that I asked question regarding the same problem but prior to this my expectation was different now my expectation is different.