Writer Macro to add blank lines only to current Selection?

I have a Writer macro that does a find/replace to add blank lines to the entire document. But sometimes I would like to do that only to a Selection and leave the rest of the document unchanged.

I did some exploration, but have gotten nowhere. Is there a straightforward way to do this?

Thanks much!

DON’T layout with blank lines!

2 Likes

Calm down. I only do this to prepare the text for pasting into online markdown editors like reddit, which don’t have paragraph spacing. Besides that, I’m looking for the ability to operate only on a selection, for use in other macros as well.

As you described your macro it looks as if it’s based on F&R. This tool on the other hand always allows to restrict the operation to the current selection if it is a single-range selection, and you simply can record a new macro with Current selection only enabled.
What I still don’t understand is if you actually just want to replace single paragraph breaks by double ones.
What I found to be an interseting task was to replace automatic line breaks (line wrapping) by hard ones, and to (probably) insert additional ones. If it’s actually this what you want to achieve, you can get my code.

Thanks. I already have a macro that converts all returns to hard. I seldom use it, but it’s one that I would add a Selection parameter to if I had the ability.

I didn’t post my macro attempts because I thought they were so poor. I was trying to get the .getString of the Selection and search within it, but kept on getting ‘object not defined’ errors. And even if it worked, using the String of the Selection would lose the formatting, which is not desirable.

Sorry. This doesn’t make sense to me. What do you mean by “convert return to hard”?

You can’t do so.
It rarely makes any sense. but if you have a task where you actually want tro treat content as “plain ASCII text” or similar, you need to use string-oriented means either provided by your programming language (Basic?) or (e.g.) done by the rather new REGEX() function. All these means only can return plain strings without any formatting.

I mean convert line wrapping to actual returns.

@paul11491: Maybe you need to change your topsecret and ingenious Makro a tiny bit:

args1(10).Name = "SearchItem.SearchFlags"
args1(10).Value = 65536  'change it to 71680'

What do you mean by line wrapping and actual returns? chr(10) or chr(13) or automatic wrapping at the end of line?

I think the best should be if you upload some example with your start text and correct result.

Sub addEnterToSelection 'add one Enter behind the selection
	dim oDoc as object, oVCur as object
	oDoc=ThisComponent
	oVCur=oDoc.CurrentController.ViewCursor 'visible cursor
	oVCur.collapseToEnd 'move cursor to the end of selection
	oVCur.string=chr(13) 'add Enter
	createUnoService("com.sun.star.frame.DispatchHelper").executeDispatch(oDoc.CurrentController.Frame, ".uno:Escape", "", 0, array()) 'deselect
End Sub
1 Like

Thanks, but this only adds a blank line after the selection.

I think it would be easier to create a paragraph style for this purpose. On the Indents & Spacing tab of the Paragraph style dialog, you can adjust the Line Spacing for this paragraph style.

Please see my reply to Karolus, above. Thank you.

Who should ever want that?
Show the macro code in such a case either by directly inserting it here as a part of your question (if short enough) or by attaching an example file containing it.
What you seem to expect your code to do sounds very strange to experienced users. They know, e.g. that many less experienced users are talking of “blank lines” where they mean blank paragraphs. Others wrongly don’t make any distinction insofar. In addition your macro should show where you actually want breaks (what do you search for)…
One might better understand what you actually want to achieve having read the code.