What do I add to my recorded macro to make it loop?

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
deguza
Posts: 13
Joined: Mon Mar 01, 2010 10:37 pm

What do I add to my recorded macro to make it loop?

Post by deguza »

Hello all:

What do I add to my macro, created by recording my keystrokes, to make it loop through a Write file?

I have spent about two hours finding answers posed to similar questions in the Open Office forums, and attempted to adapt the solutions offered to my macro, but none would work.

Any help would be appreciated.

Deguza

Code: Select all

REM  *****  BASIC  *****


sub B_Y

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 = 65536
args1(10).Name = "SearchItem.SearchString"
args1(10).Value = "n_"
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

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:GoRight", "", 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 ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:WordRightSel", "", 0, Array())

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

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

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

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

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

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:GoLeft", "", 0, args8())

rem ----------------------------------------------------------------------
dim args9(0) as new com.sun.star.beans.PropertyValue
args9(0).Name = "Text"
args9(0).Value = "[["

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

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

rem ----------------------------------------------------------------------
dim args11(0) as new com.sun.star.beans.PropertyValue
args11(0).Name = "Text"
args11(0).Value = "]]"

dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args11())

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

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

end sub
OpenOffice 4.1.3 Windows 10
User avatar
Zizi64
Volunteer
Posts: 11352
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: What do I add to my recorded macro to make it loop?

Post by Zizi64 »

What do I add to my macro, created by recording my keystrokes, to make it loop through a Write file?
Do you mean it: you want to repeat (run it more than one) the recorded macro when it will launch?

Do you know anything about the 'For...Next', 'Do...While', 'Do...Until' cyclic program loops?


'Recording a macro' it means for me: you are not a programmer. You need study the Help of the StarBasic, the descriptions of the API functions, and the free books written by Andrew Pitonyak - if you want to WRITE a macro, or a part of a macro.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
deguza
Posts: 13
Joined: Mon Mar 01, 2010 10:37 pm

Re: What do I add to my recorded macro to make it loop?

Post by deguza »

Hello Tibor,

I know about program loops.

I had perused through the sources you have cited for about an hour before posting my initial question. However, I could not figure out what to do. Hence I am here.

Do you have any suggestions?

Thanks in advance.

Deguza
Last edited by deguza on Thu Jun 15, 2017 7:24 am, edited 1 time in total.
OpenOffice 4.1.3 Windows 10
JeJe
Volunteer
Posts: 2763
Joined: Wed Mar 09, 2016 2:40 pm

Re: What do I add to my recorded macro to make it loop?

Post by JeJe »

Instead of using the dispatch helper for your search use what's on this page here.

https://wiki.openoffice.org/wiki/Docume ... _Documents
Found = Doc.findFirst (SearchDesc)

Do Until IsNull(Found)
' Edit search results...
Found = Doc.findNext( Found.End, SearchDesc)
Loop
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Post Reply