[Solved] Recorded macro, Advanced Filtering - fails to copy

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
amund88
Posts: 1
Joined: Sun Jan 29, 2017 7:21 pm

[Solved] Recorded macro, Advanced Filtering - fails to copy

Post by amund88 »

I have a set of data in Sheet2 C1-D8. Row C contains criteria values, row D contains data values.
Criteria range for use by Advanced Filtering are defined in Sheet2 I1-J2.

I use Data-Filter-Advanced Filtering to copy the filtered results from Sheet2 C1-D8 into Sheet3 A1. This works well when done manually by myself while recording the macro.
However, when I run the macro, nothing happens - the filter results are not copied over to Sheet3 A1.

I have taken a look at the recorded macro, and there is no mention here of the cells which contain the criteria range (Sheet2 I1-J2) or the cell to which the results should be copied, Sheet3 A1.

Please see below code from the recorded macro, there must be something missing in the code. I'm stuck...

Code: Select all

sub forum
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "ToPoint"
args1(0).Value = "$C$1:$D$8"

dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args1())

rem ----------------------------------------------------------------------
rem dispatcher.executeDispatch(document, ".uno:DataFilterSpecialFilter", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:FilterExecute", "", 0, Array())


end sub
Last edited by amund88 on Mon Jan 30, 2017 10:56 pm, edited 1 time in total.
OpenOffice 4.1.3 - Windows 7 Service Pack 1
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Recorded macro, Advanced Filtering - fails to copy when

Post by Villeroy »

Recorded macros simulate actions in the GUI. YOu won't get far with that.
download/file.php?id=136 demonstrates how to do this with a macro.
It uses a database range "Import1" and a named range "criteria" for the filter criteria. While typing into a text box, you trigger a modification event of that box which calls the macro with every key stroke.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply