[Solved] Remove spaces macro problem

The Application Programming Interface and the OASIS Open Document Format

[Solved] Remove spaces macro problem

Postby eatc7402 » Wed May 04, 2011 4:04 am

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   Expand viewCollapse view
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   Expand viewCollapse view
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
eatc7402
 
Posts: 4
Joined: Wed May 04, 2011 3:52 am

Re: Remove spaces macro problem

Postby FJCC » Wed May 04, 2011 4:26 am

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   Expand viewCollapse view
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())
Windows 10 and Linux Mint, since 2017
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 7480
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Remove spaces macro problem

Postby eatc7402 » Wed May 04, 2011 4:44 am

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
eatc7402
 
Posts: 4
Joined: Wed May 04, 2011 3:52 am


Return to UNO API and ODF

Who is online

Users browsing this forum: No registered users and 1 guest