The ranges don't have to be adjacent, once the selecting is done, I want copy the strings in the ranges, into the clipboard, without using ctrl button, or any keyboard input in general, and without making any change on the sheet.
I have set nearly all the macro necessary, without a problem. but the listeners go out of control.
I need a listener to keep former selected range address in memory and add the new selected range address into the former one.
a macro linked to selection change listener repeats itself more than one time as if ctrl is pressed, while the mouse cursor is moved it keeps chosing new ranges whereever the cursor is moved to.
how can I avoid this. I don't want to remove the listener, because it's supposed to work if I select a new range. but as summary, that code cause the openoffice work as if the ctrl is pressed.
Code: Select all
Option Explicit
Public oListener As Object
Public oDocView As Object
Public oSelMem 'As Object
'run this macro to start event intercepting
Sub Example_SelectionChangeListener
Dim sName$
'Dim oSelMem
oDocView = ThisComponent.getCurrentController
'create a listener to intercept the selection change event
sName = "com.sun.star.view.XSelectionChangeListener"
oListener = CreateUnoListener( "MyApp_", sName )
' register the listener to the document controller
oDocView.addSelectionChangeListener(oListener)
oSelMem = Replace(ThisComponent.CurrentSelection.Absolutename, "$", "")
End Sub
'run this macro to stop event intercepting
Sub Remove_Listener
dim oDocView
' removes the listener
ThisComponent.getCurrentController.removeSelectionChangeListener(oListener)
End Sub
'all listeners must support this event
Sub MyApp_disposing(oEvent)
msgbox "disposing the listener"
End Sub
Sub MyApp_selectionChanged(oEvent)
Dim oarrow
oarrow = " <=> "
Dim oCurrentSelection As Object
Dim nCurSel
Dim ros
'the source property of the event struct
'gets a reference to the current selection
oCurrentSelection = oEvent.source
'MsgBox oCurrentSelection.dbg_properties
nCurSel = Replace(ThisComponent.CurrentSelection.Absolutename, "$", "")
ros = right(oselmem, len(ncursel) )
' msgbox ros & oarrow & ncursel
if ros = ncursel then
' msgbox right(oselmem, len(ncursel)) = ncursel
' msgbox ros = ncursel
' Remove_Listener
oSelMem = oSelMem
else
oSelMem = oSelmem & chr(10) & nCursel
'msgbox """" & right(oselmem, len(ncursel)) & """" & oarrow & """" & ncursel & """" & chr(10) & """" & oSelMem & """"
test_oSelMem
end if
End Sub
Sub Test_oSelMem
msgbox oSelMem
End Sub