[Solved] [Writer] Duplicate paragraphs via Basic macro
[Solved] [Writer] Duplicate paragraphs via Basic macro
Hello, I would like to copy the first 3 paragraphs of a writer document at the end of the document
Last edited by patel on Sat Apr 18, 2020 8:00 am, edited 2 times in total.
OpenOffice 4.1 on Windows 10
LibreOffice 5.2 on Windows 10
LibreOffice 5.2 on Windows 10
Re: [Writer] Duplicate paragraphs via basic macro
If you read up on text cursors.
https://wiki.openoffice.org/wiki/Writer/API/Text_cursor
https://wiki.openoffice.org/wiki/Writer/API/Text_cursor
Code: Select all
REM ***** BASIC *****
Sub Main
doc = thiscomponent
vc = doc.currentcontroller.viewcursor
tc = doc.text.createtextcursorbyrange(doc.text.getstart)
for i =1 to 3
tc.gotoNextParagraph(true)
next
doc.currentcontroller.select(tc)
trans = doc.currentcontroller.gettransferable
tc.gotorange(doc.text.getend,false)
doc.currentcontroller.select(tc)
doc.currentcontroller.inserttransferable(trans)
End Sub
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: [Writer] Duplicate paragraphs via basic macro
Perfect, thank you very much.
OpenOffice 4.1 on Windows 10
LibreOffice 5.2 on Windows 10
LibreOffice 5.2 on Windows 10
Re: [Writer] Duplicate paragraphs via Basic macro
how can I change the code to copy paragraphs 3 to 5? or the selected paragraphs)
OpenOffice 4.1 on Windows 10
LibreOffice 5.2 on Windows 10
LibreOffice 5.2 on Windows 10
Re: [Writer] Duplicate paragraphs via Basic macro
You must study the API descriptions of the AOO/LO - and read Andrew Pitonyak"s free macro books.or the selected paragraphs)
API: Application Programming Interface.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
Re: [Writer] Duplicate paragraphs via Basic macro
The line
copies the selected text.
Play around with the following bit and what you learn by reading the above link I posted: work through that page till you understand it then you'll be able to answer the change of paragraphs bit yourself. I'm not giving you the whole answer cause we'll be here forever with someone writing all your code for you and you never learning how to do it for yourself.
Code: Select all
trans = doc.currentcontroller.gettransferable
Play around with the following bit and what you learn by reading the above link I posted: work through that page till you understand it then you'll be able to answer the change of paragraphs bit yourself. I'm not giving you the whole answer cause we'll be here forever with someone writing all your code for you and you never learning how to do it for yourself.
Code: Select all
for i =1 to 3
tc.gotoNextParagraph(true)
next
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: [Writer] Duplicate paragraphs via Basic macro
my solution
Code: Select all
Sub CopySelection
Doc = thiscomponent
trans = doc.currentcontroller.gettransferable
tc = doc.text.createtextcursorbyrange(doc.text.getend)
doc.currentcontroller.select(tc)
doc.currentcontroller.inserttransferable(trans)
end sub
OpenOffice 4.1 on Windows 10
LibreOffice 5.2 on Windows 10
LibreOffice 5.2 on Windows 10