how to repeat a macro

I am using Version: (x64) of Libre office. I recorded a macro to delete the “enter” at the end of a line. Now I would like to have this macro repeat until the end of the document. How do I do that? Here is the code:

sub DelEndSpace

rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object

rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("")

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:GoToEndOfLine", "", 0, Array())

rem ----------------------------------------------------------------------
dim args2(0) as new
args2(0).Name = "Text" 
args2(0).Value = " "
dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args2())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Delete", "", 0, Array())

end sub

[Edit - Opaque] put code into preformatted text

There are several answers for your question.

The easiest one: assign a hotkey to your macro (for example, Shift+Delete) via the Tools - Customize - Keyboard menu. Now just press and hold these keys until you see your entire document turn into one long paragraph.

Moderately difficult option: rewrite your macro, but use not “jump to the end of the line and write a space”, but “search for the end of the line and replace with a space”. In this case, your code will immediately replace all line ends with spaces in one go, no loop is needed.


The most difficult way (for you now it is really difficult, perhaps someday later): I will not describe it, it has been described many times. This is best described in the book by Andrew Pitonyak (eg chapter 7.14.4. Search and Replace with Attributes and Regular Expressions)

An unbearably difficult decision: try searching this resource for the answer. If you are lucky, then very quickly you will find, for example, this question and the answers to it.