Greetings to all, I’m new to the forum , sorry for my poor english.
I’m designing a macro to search for text in writers but only within a selected text
The purpose is to search for a text, select the instances found, perform a new search on the new selected text to perform nested searches
From the menu it is sufficient to activate the “search only in selection” checkbox.
Using the macro recorder the output is:
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService ("com.sun.star.frame.DispatchHelper")
dim args1 (21) 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.SearchFiltered"
args1 (4) .Value = false
........
........
args1 (19) .Value = false
args1 (20) .Name = "SearchItem.AlgorithmType2"
args1 (20) .Value = 1
args1 (21) .Name = "Quiet"
args1 (21) .Value = true
dispatcher.executeDispatch (document, ".uno: ExecuteSearch", "", 0, args1 ())
The property involved should be SearchFiltered or something similar, but I can’t find any documentation about it.
Furthermore, SearchFiltered does not appear in the properties of the createSearchDescriptor object.
I tried to make the following macro run on the current document with a selected text segment:
oDoc = ThisComponent
oDesc = oDoc.createSearchDescriptor ()
oDesc.searchWords = TRUE
oDesc.SearchString = “little”
Dim q (0) as new com.sun.star.beans.PropertyValue
q (0) .Name = “SearchFiltered”
q (0) .Value = true
oDesc.SetSearchAttributes (q ())
oFound = oDoc.findAll (oDesc)
The oDesc.SetSearchAttributes (q ()) statement causes the runtime error due to an exception with the unexplained message Type: com.sun.star.beans.UnknownPropertyException Message:.
I searched for a long time on the net but I didn’t find any examples, i don’t understand how to search for text in a selection with a macro, while I didn’t have any problem searching for texts and styles with macros
How to solve the problem?