Multiple Selections in Writer by macro
Posted: Sat Aug 19, 2023 2:30 am
We can do it with dispatch commands. Example below should create two separate selections in a document with some text that begins in the normal selection mode.
(Another way is to mark the text in some way such as with charflash and then do a find for charflash - unfortunately that produces a selection comprised of the text of each paragraph, not the full text including paragraph end marks)
(Another way is to mark the text in some way such as with charflash and then do a find for charflash - unfortunately that produces a selection comprised of the text of each paragraph, not the full text including paragraph end marks)
Code: Select all
sub test
godown 2,true 'select 2 lines
for i = 0 to 1 'turn on selection mode ASSUMES WE BEGAN WITH NORMAL (STD) selection mode
selectionMode
next
godown 2,false 'go down 2 linew without selecting
goright 10,true 'go right 10 characters selecting
end sub
sub selectionMode
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dispatcher.executeDispatch(document, ".uno:SelectionMode", "", 0, Array())
end sub
sub GoDown(n, doselect)
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(1) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Count"
args1(0).Value = n
args1(1).Name = "Select"
args1(1).Value = doselect
dispatcher.executeDispatch(document, ".uno:GoDown", "", 0, args1())
end sub
sub goRight(n,doselect)
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(1) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Count"
args1(0).Value = n
args1(1).Name = "Select"
args1(1).Value = doselect
dispatcher.executeDispatch(document, ".uno:GoRight", "", 0, args1())
end sub