[Solved] Macro to create 1-sentence paragraphs
[Solved] Macro to create 1-sentence paragraphs
Hi
I am looking for a macro to find the end of a sentence in the text and move it to the beginning of a new line. Modify all text to form one sentence one line.
I was looking for but did not find ..
I am looking for a macro to find the end of a sentence in the text and move it to the beginning of a new line. Modify all text to form one sentence one line.
I was looking for but did not find ..
Last edited by MrProgrammer on Wed Mar 31, 2021 6:37 pm, edited 2 times in total.
Reason: Tagged ✓ [Solved]
Reason: Tagged ✓ [Solved]
Open Office 4.1.0 / LibreOffice 7.1 on Windows 10 Home
Re: Macro in Writer
Why use a macro? This can be done with three or four passes of Find and Replace - one if you use a Regular expression.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
Re: Macro in Writer
HiRoryOF wrote:Why use a macro? This can be done with three or four passes of Find and Replace - one if you use a Regular expression.
It needs to be automated. I have, for example, 200 text, one click and change of the entire document.
***************************
I wanted to traverse each paragraph and possible change the paragraph styles. To do this, I needed to select one paragraph at a time. My first attempt, which was wrong, involved a starting point of having a paragraph selected. I then moved right zero spaces to remove the selection from the current paragraph.
macro
I wanted to traverse each paragraph and possible change the paragraph styles.
To do this, I needed to select one paragraph at a time.
My first attempt, which was wrong, involved a starting point of having a paragraph selected.
I then moved right zero spaces to remove the selection from the current paragraph.
Open Office 4.1.0 / LibreOffice 7.1 on Windows 10 Home
Re: Macro in Writer
Please define "end of a sentence".
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
Re: Macro in Writer
End of sentence. < dotRoryOF wrote:Please define "end of a sentence".
Open Office 4.1.0 / LibreOffice 7.1 on Windows 10 Home
Re: Macro to create 1-sentence paragraphs
What about ? ! " '
You have to think this out.
You have to think this out.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
Re: Macro to create 1-sentence paragraphs
menu:Edit>Find&Replace....
[X] Regular expresssion
Find: ([.?!])[:space:]*
Replace: $1\n
[Replace All]
replaces points, ? and ! followed by optional space with point, ? or ! and a paragraph break.
[X] Regular expresssion
Find: ([.?!])[:space:]*
Replace: $1\n
[Replace All]
replaces points, ? and ! followed by optional space with point, ? or ! and a paragraph break.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: Macro to create 1-sentence paragraphs
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
- MrProgrammer
- Moderator
- Posts: 4908
- Joined: Fri Jun 04, 2010 7:57 pm
- Location: Wisconsin, USA
Re: Macro to create 1-sentence paragraphs
Hi, and welcome to the forum.
• Edit → Find & Replace → More options, ✓ Regular Expressions, Search for \.\s+, Replace with .\n, Replace All.
Your macro is very simple because it only requires one step. Call it (Tools → Macros → Run macro) whenever you need it. Or use a keyboard shortcut, menu, or toolbar to run it.
How can I record a macro?
[Tutorial] Binding a macro: Shortcut key, menu or toolbar
If this solved your problem please go to your first post use the Edit button and add [Solved] to the start of the subject field. Select the green checkmark icon at the same time.
Last One wrote:… find the end of a sentence in the text and move it to the beginning of a new line.
Last One wrote:It needs to be automated.
Record a macro. You do this once as described in Help → Index → recording;macros. You don't need to know any programming but you do need to learn about how to record a macro. Then record this one action.Last One wrote:End of sentence. < dot
• Edit → Find & Replace → More options, ✓ Regular Expressions, Search for \.\s+, Replace with .\n, Replace All.
Your macro is very simple because it only requires one step. Call it (Tools → Macros → Run macro) whenever you need it. Or use a keyboard shortcut, menu, or toolbar to run it.
How can I record a macro?
[Tutorial] Binding a macro: Shortcut key, menu or toolbar
If this solved your problem please go to your first post use the Edit button and add [Solved] to the start of the subject field. Select the green checkmark icon at the same time.
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.6.3, iMac Intel. The locale for any menus or Calc formulas in my posts is English (USA).
AOO 4.1.7 Build 9800, MacOS 13.6.3, iMac Intel. The locale for any menus or Calc formulas in my posts is English (USA).
Re: Macro to create 1-sentence paragraphs
Something like this for the textcursor method. (test on a copy of your document with just the text you want converted in it.)
Code: Select all
Sub ConvertToSentences()
txt = thiscomponent.text
tc= txt.createtextcursorbyrange(txt.start)
do
ret = tc.gotoEndOfSentence(false)
if ret = 0 then exit do
tc.goright(1,true)
if tc.string=" " then
tc.string =""
else
if tc.string <> chr(10) then tc.Text.insertControlCharacter(tc,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, True)
end if
tc.collapsetoend
tc.goright(1,false)
loop
End Sub
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)