I am trying to learn writing macro in OO and find the documentation really frustrating so I turned here for help.
I have a macro that works fine in the Sheet:double click event. When I assign it to the Selection change event it runs 3 to 4 times. To try to debug it I wrote a simple macro that has one line: Msgbox "Selection Change"
Sure enough the msgbox box pops up 4 times for each Selection change event. What am I missing? Is there any online documentation where I can learn?
Thanks very much
Sheet Event Selection Change runs Macro 4 times
Sheet Event Selection Change runs Macro 4 times
OpenOffice 4.1.3 on Windows 10
Re: Sheet Event Selection Change runs Macro 4 times
- What version are you using really?OpenOffice 3.2 on Windows XP
- Can you upload your ODF type sample file with the embedded macro code here?
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.
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.
Re: Sheet Event Selection Change runs Macro 4 times
Windows 10
OO 4.1.3
My real macro and test macro exhibit the same behavior: running 4 times for each selection change. So here's is my test macro which is assigned to the selection change event:
Sub Main
Msgbox " Selection Change"
end Sub
OO 4.1.3
My real macro and test macro exhibit the same behavior: running 4 times for each selection change. So here's is my test macro which is assigned to the selection change event:
Sub Main
Msgbox " Selection Change"
end Sub
OpenOffice 4.1.3 on Windows 10
Re: Sheet Event Selection Change runs Macro 4 times
Please upload your sample file.
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.
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.
Re: Sheet Event Selection Change runs Macro 4 times
Here is the test file. Thanks
- Attachments
-
- Test.ods
- (9.54 KiB) Downloaded 200 times
OpenOffice 4.1.3 on Windows 10
Re: Sheet Event Selection Change runs Macro 4 times
As soon as you do the MouseButtonDown the sub starts and displays the message without detaching the mouse movement from the process of selecting. While you try to move the mouse pointer to the OK button, the selection is expanded and a new call to the sub is queued...
It's not a bug, it's a problem.
Well, it may be seen as a bug. But event driven software/programming comes with perils.
You may want to play with my demo which puts the message about the changed selection into the first cell of the selection itself and does not prompt for an OK.
(No. I do not know how to exit the process of selection from the sub's body.)
It's not a bug, it's a problem.
Well, it may be seen as a bug. But event driven software/programming comes with perils.
You may want to play with my demo which puts the message about the changed selection into the first cell of the selection itself and does not prompt for an OK.
(No. I do not know how to exit the process of selection from the sub's body.)
- Attachments
-
- a0092334SelectionChangedDemo_1.ods
- (10.18 KiB) Downloaded 238 times
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
---
Lupp from München
Re: Sheet Event Selection Change runs Macro 4 times
Yes the Mouse is the issue.
To better explain the situation I've modified your Macro which shows the behavior better:
This code grabs the right most character of the AbsoluteName and changes it to an integer. It will then add this value to the value of the selected cell.
if you use the mouse to select a cell, that value will be added 4 times. If you use the up,down keys, the macro runs just once as it should.
This macro assigned to the double click event will work properly with the mouse.
Sub testSelChg(pEvent)
aN = pEvent.AbsoluteName
row = cInt(right(aN,1))
If pEvent.SupportsService("com.sun.star.sheet.SheetCellRanges") Then
rG = pEvent(0)
Else
rG = pEvent
End If
c0 = rG.GetCellByPosition(0,0)
c0.Value =c0.value + row
End Sub
To better explain the situation I've modified your Macro which shows the behavior better:
This code grabs the right most character of the AbsoluteName and changes it to an integer. It will then add this value to the value of the selected cell.
if you use the mouse to select a cell, that value will be added 4 times. If you use the up,down keys, the macro runs just once as it should.
This macro assigned to the double click event will work properly with the mouse.
Sub testSelChg(pEvent)
aN = pEvent.AbsoluteName
row = cInt(right(aN,1))
If pEvent.SupportsService("com.sun.star.sheet.SheetCellRanges") Then
rG = pEvent(0)
Else
rG = pEvent
End If
c0 = rG.GetCellByPosition(0,0)
c0.Value =c0.value + row
End Sub
- Attachments
-
- SelectionChangedDemo_PutCellRow.ods
- (10.17 KiB) Downloaded 236 times
OpenOffice 4.1.3 on Windows 10