Find & replace in Text Box

I need to add quite some code snippets into a writer document. As I want to give those a constant background color I was thinking to use text boxes for this.

I’ll have to adjust timestamps in those code snippets though and can not manage to operate find & replace (ctrl +h) inside a text box. Is there a way to do that?

Ideally, you would use a paragraph style for Code. You can set a background color for the paragraph style as well as font, etc.

If you wanted the code to lie outside the main body of the work you could use frames rather than text boxes. Insert - Frame and you have a choice of interactively or by dialogue box.

Cheers, Al

3 Likes

In addition to @EarnestAl ,
If you want to use code snippets within a paragraph, you can use a character style instead.

I assume that you basically work with styles and do not format directly. This could lead to unwanted results if you use direct formatting and style sheets at the same time.


Professional text composition with Writer

3 Likes

It is possible with macro, but it is not so easy :-(.

Sub TextBoxes
	dim oDoc as object, oDrawpage as object, o as object, i&
	oDoc=ThisComponent
	oDrawpage=oDoc.Drawpage
	for i=0 to oDrawpage.Count-1
		o=oDrawpage.getByIndex(i)
		if o.supportsService("com.sun.star.drawing.TextShape") then
			'xray o 'actual Text Box
			msgbox o.String
		end if
	next
End Sub

For string in TextBox you can use classical commands Left/Right/Mid or createTextCursor() or Text Search com.sun.star.util.TextSearch.

1 Like

no macros for me! thx anyway for sharing that wisdom.

1 Like