[Solved] Recorded macro for...next, loop

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
BubikolRamios
Posts: 91
Joined: Sat Jan 04, 2014 1:28 pm

[Solved] Recorded macro for...next, loop

Post by BubikolRamios »

recorded macro, works as intended,need to repeat itself a couple (+/-25.000) of times, so only thing I added is for/next.
Goes into exception, no idea where to put for/next did couple of test in blind, no success ...

Code: Select all

REM  *****  BASIC  *****
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 = 1
args1(9).Name = "SearchItem.SearchFlags"
args1(9).Value = 65536
args1(10).Name = "SearchItem.SearchString"
args1(10).Value = "^[A-Z]\."
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 = 0
args1(18).Name = "Quiet"
args1(18).Value = true


dim i
For i = 1 To 9


dispatcher.executeDispatch(document, ".uno:ExecuteSearch", "", 0, args1())

rem ----------------------------------------------------------------------
dim args2(1) as new com.sun.star.beans.PropertyValue
args2(0).Name = "Count"
args2(0).Value = 1
args2(1).Name = "Select"
args2(1).Value = false

dispatcher.executeDispatch(document, ".uno:GoLeft", "", 0, args2())

rem ----------------------------------------------------------------------
dim args3(1) as new com.sun.star.beans.PropertyValue
args3(0).Name = "Count"
args3(0).Value = 1
args3(1).Name = "Select"
args3(1).Value = false

dispatcher.executeDispatch(document, ".uno:GoLeft", "", 0, args3())

rem ----------------------------------------------------------------------
dim args4(1) as new com.sun.star.beans.PropertyValue
args4(0).Name = "Count"
args4(0).Value = 1
args4(1).Name = "Select"
args4(1).Value = false

dispatcher.executeDispatch(document, ".uno:GoUp", "", 0, args4())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:WordRightSel", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:GoToStartOfLine", "", 0, Array())

rem ----------------------------------------------------------------------
dim args8(1) as new com.sun.star.beans.PropertyValue
args8(0).Name = "Count"
args8(0).Value = 1
args8(1).Name = "Select"
args8(1).Value = false

dispatcher.executeDispatch(document, ".uno:GoDown", "", 0, args8())

rem ----------------------------------------------------------------------
dim args9(1) as new com.sun.star.beans.PropertyValue
args9(0).Name = "Count"
args9(0).Value = 1
args9(1).Name = "Select"
args9(1).Value = false

dispatcher.executeDispatch(document, ".uno:GoRight", "", 0, args9())

rem ----------------------------------------------------------------------
dim args10(1) as new com.sun.star.beans.PropertyValue
args10(0).Name = "Count"
args10(0).Value = 1
args10(1).Name = "Select"
args10(1).Value = false


dispatcher.executeDispatch(document, ".uno:GoRight", "", 0, args10())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:SwBackspace", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:SwBackspace", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Paste", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:SwBackspace", "", 0, Array())

next i

end sub
Text to test, caret at start:
Abrothallus caerulescens
A. Cetrariae
A. cladoniae
A. hypotrachynae
A. microspermus

Last edited by BubikolRamios on Sun Sep 04, 2022 10:44 pm, edited 1 time in total.
OPen office 4.1.5/ win 7
JeJe
Volunteer
Posts: 2763
Joined: Wed Mar 09, 2016 2:40 pm

Re: recorded macro for...next, loop

Post by JeJe »

move all the property value declarations to before the for-next

Code: Select all



dim args2(1) as new com.sun.star.beans.PropertyValue
args2(0).Name = "Count"
args2(0).Value = 1
args2(1).Name = "Select"
args2(1).Value = false

'etc etc

For i = 1 To 9

Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
BubikolRamios
Posts: 91
Joined: Sat Jan 04, 2014 1:28 pm

Re: recorded macro for...next, loop

Post by BubikolRamios »

Works.
Thanks.
OPen office 4.1.5/ win 7
Post Reply