Ask Your Question
0

Can this be done with a macro? If so, what would that macro look like?

asked 2019-04-15 00:23:21 +0200

That_Guy gravatar image

I'm working on a large document and would like to be able to select several different sections of text, press a button or two, and have strings of text appear both before and after the selected text. As an example of what I'm after:

Step 1.
In this sentence, I select this bit of text and then use ctrl to also select this second bit of text and this third bit of text.

Step 2.
I enter a command that executes a macro.

Result:
In this sentence, I select < desired string of before text > this bit of text < desired string of after text > and then use ctrl to also select < desired string of before text > this second bit of text < desired string of after text > and < desired string of before text > this third bit of text < desired string of after text >.

I should note that I have AutoText commands set up that can be used to generate the desired text strings, but relying solely on those will take days of tedious repetition to get the desired results. I'm hoping a macro can drastically reduce the time needed to accomplish this, but I do not possess the knowledge or understanding necessary to create such a macro. Is it possible to write a macro that can do this? If so, what would that macro look like?

edit retag flag offensive close merge delete

Comments

No need for Makro, do Step1 and look at my Answer.

karolus gravatar imagekarolus ( 2019-04-15 09:11:19 +0200 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2019-04-15 09:01:00 +0200

karolus gravatar image

updated 2019-04-15 19:12:34 +0200

Hi.

Search and replace
Search (.*).
Replace with textbefore $1 textafter.
with Options: [✓]regular Expressionand[✓] Selection only
and press the obvious Replace All Button

Sorry for the wrong answer above, I've missed the point that [x] selection only is not available in multiselection-mode.

So try this:

Sub Main

Textbefore = "put in here whatever you want"
Textafter =  "and here also"

doc = thisComponent
selections = doc.CurrentSelection

for i = 1 to selections.Count-1
    selections(i).String = Textbefore & selections(i).String & Textafter
next


End Sub
edit flag offensive delete link more

Comments

There is currently no text before or after the desired sections. I was hoping to create a macro that would add one text string to the beginning of selected sections of text and add a different text string to the ends of those sections.

That_Guy gravatar imageThat_Guy ( 2019-04-15 15:19:24 +0200 )edit

Thats exactly whats my suggested search & replace procedure does.
any Questions?

karolus gravatar imagekarolus ( 2019-04-15 16:09:36 +0200 )edit

Doing that replaces the selected text with the string intended to go in front of it. What I'm trying to do is this:

Take the following sentence:

"Attach the flibbertyjibbit to the thing-a-ma-whatsit and use the resulting rejimotus to confuse a cat."

Select the words flibbertyjibbit,thing-a-ma-whatsit, and rejimotus in the sentence, enter a single command, and get this result:

"Attach the < desired string of before text >flibbertyjibbit< desired string of after text > to the < desired string of before text >thing-a-ma-whatsit< desired string of after text > and use the resulting < desired string of before text >rejimotus< desired string of after text > to confuse a cat."

That_Guy gravatar imageThat_Guy ( 2019-04-15 17:07:45 +0200 )edit

Please see my edited answer, sorry for the misleading advice.

karolus gravatar imagekarolus ( 2019-04-15 19:14:48 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-04-15 00:23:21 +0200

Seen: 52 times

Last updated: Apr 15