See above.
oEventListener = CreateUnoListener("EventListener_", "com.sun.star.util.XModifyListener")
Sub EventListener_modified(oEvent)
' ...
End Sub
See above.
oEventListener = CreateUnoListener("EventListener_", "com.sun.star.util.XModifyListener")
Sub EventListener_modified(oEvent)
' ...
End Sub
Corrected. Well, my error disapeared, but Calc crashes…
Global oEventListener As Object
Sub StartEventListener()
Dim oTable1 As Object
oTable1 = ThisComponent.Sheets.getByName("PivotTables").DataPilotTables.getByName("DataPilot1")
If IsNull(oEventListener) Then 'just to be shure it doesn't start twice
oEventListener = CreateUnoListener("EventListener_", "com.sun.star.util.XModifyListener")
oTable1.addModifyListener(oEventListener)
End If
End Sub
Sub StopEventListener()
Dim oTable1 As Object
oTable1 = ThisComponent.Sheets.getByName("PivotTables").DataPilotTables.getByName("DataPilot1")
If Not IsNull(oEventListener) Then 'only if still running
oTable1.removeModifyListener(oEventListener)
oEventListener = Nothing 'to know later the listener has stopt
End If
End Sub
Sub EventListener_queryInterface(oEvent As Object)
End Sub
Sub EventListener_disposing(oEvent)
MsgBox "EventListener_disposing does work now !?"
Call StopEventListener
End Sub
Sub EventListener_modified(oEvent As Object)
Call SyncDataPilotsByFilter
End Sub
File attached, updated:
2pivots-connected-to-filter.ods (20.7 KB)
Replace in EventListener_modified
body to
Msgbox "Pivot table modified"
If changing the pivot table works then the problem is in SyncDataPilotsByFilter
.
SyncDataPilotsByFilter works when called manually.
Yes, the listener works, but when SyncDataPilotsByFilter is called from EventListener_modified event, a crash occurs. What can be done?
UPDATED:
And we also need to find where the names of the events are hidden in order to skip those that we do not need here.
I now have no opportunity for a detailed analysis.
Perhaps this is a bug. Try to refresh the second pivot table in the EventListener_modified
procedure without any modification.
There is another problem. When I manually sync the second table by SyncDataPilotsByFilter, the EventListener_modified event of the first table fires. Why?
Or the same.
@kesu, you can consider another cool way to connect multiple pivot tables to a common data source and filter them at the same time.
There is a dataset. Above it is a range of Advanced Filter criteria. By the way, you can position the criteria range anywhere. You can filter the data even better here because the OR operator is also supported (only AND in pivot tables*). The filtered data is copied to another location (Copy results to output range) on the hidden sheet. And all the pivot tables are connected to this output range. Data is filtered as input to pivot tables, and tables always display complete data.
Works great!
But we need to automate a little. Very little. If this is what you need…
_______
* However, the Standard filter can do that too. This is not in Excel, just as there is no possibility to use regular expressions.
UPDATED:
If there is time and people willing to help the author with this task, I will give one more tip.
The programming of this task will become much easier if create a database range instead of a named range and use structured references to table, headers, columns, etc. (i.e. references in square brackets, who knows). This greatly simplifies the task: nothing needs to be calculated. It doesn’t matter that they are then converted to absolute references.
By the way, in Excel, this method is used just then to use the OR operator in pivot tables. But why don’t we connect multiple tables to the data source for our purposes?
https://forum.openoffice.org/en/forum/download/file.php?id=31296 is the database PowerFilter.odb from the topic I have linked on Nov 21 2021. Register the database as “PowerFilter”.
Open the attached spreadheet. I has 4 lines of macro code refreshing the pivots.
Play with the filter form.
PowerFilter_JoinPivots.ods (23.9 KB)
P.S. there is a date formatting problem I don’t care about yet. Works fine with OpenOffice.
P.P.S. LO crashes when I activate the second sheet of the original spreadsheet https://forum.openoffice.org/en/forum/download/file.php?id=31689 just another LO regression with database context.