[Solved] Remove spaces macro problem

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
eatc7402
Posts: 4
Joined: Wed May 04, 2011 3:52 am

[Solved] Remove spaces macro problem

Post by eatc7402 »

I'm trying to create what I thought should have been a simple macro to record. Hmmm... wishfull
thinking.

I need a macro to 1 to X number of space characters from a text selection.
Such as if I had...

Code: Select all

one     two        three
and I selected from the 'e' at the end of the 'one' to the 't' at the beginning
of the 'two' and then ran my macro I would get...

Code: Select all

onetwo       three
Simple, or so I thought. I cannot seem to figure out how to record such a macro.

eatc7402
Last edited by Hagar Delest on Wed May 04, 2011 8:21 am, edited 1 time in total.
Reason: tagged [Solved].
OpenOffice 3.1 on Windows 7
FJCC
Moderator
Posts: 9274
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Remove spaces macro problem

Post by FJCC »

This could be more elegantly done writing a macro rather than using the recorder. I tried the recorder and the code I got is posted below. All I did was highlight some text, start the Macro Recorder, click on the Find & Replace icon, type a space into the Search For box, leave the Replace With box blank, click on More Options and select Current Selection Only, click on Replace All. I then stopped the macro recorder and saved the macro within the document.

Code: Select all

sub Main
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("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim args1(18) as new com.sun.star.beans.PropertyValue
args1(0).Name = "SearchItem.StyleFamily"
args1(0).Value = 2
args1(1).Name = "SearchItem.CellType"
args1(1).Value = 0
args1(2).Name = "SearchItem.RowDirection"
args1(2).Value = true
args1(3).Name = "SearchItem.AllTables"
args1(3).Value = false
args1(4).Name = "SearchItem.Backward"
args1(4).Value = false
args1(5).Name = "SearchItem.Pattern"
args1(5).Value = false
args1(6).Name = "SearchItem.Content"
args1(6).Value = false
args1(7).Name = "SearchItem.AsianOptions"
args1(7).Value = false
args1(8).Name = "SearchItem.AlgorithmType"
args1(8).Value = 0
args1(9).Name = "SearchItem.SearchFlags"
args1(9).Value = 71680
args1(10).Name = "SearchItem.SearchString"
args1(10).Value = " "
args1(11).Name = "SearchItem.ReplaceString"
args1(11).Value = ""
args1(12).Name = "SearchItem.Locale"
args1(12).Value = 255
args1(13).Name = "SearchItem.ChangedChars"
args1(13).Value = 2
args1(14).Name = "SearchItem.DeletedChars"
args1(14).Value = 2
args1(15).Name = "SearchItem.InsertedChars"
args1(15).Value = 2
args1(16).Name = "SearchItem.TransliterateFlags"
args1(16).Value = 1280
args1(17).Name = "SearchItem.Command"
args1(17).Value = 3
args1(18).Name = "Quiet"
args1(18).Value = true

dispatcher.executeDispatch(document, ".uno:ExecuteSearch", "", 0, args1())
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
eatc7402
Posts: 4
Joined: Wed May 04, 2011 3:52 am

Re: Remove spaces macro problem

Post by eatc7402 »

Yes that fixes it. I retried my recordeing with your 'model' as an example, and it now
does what I need it to do. Thanks.

eatc7402
OpenOffice 3.1 on Windows 7
Post Reply