I have the same question and tried the solution without success. I've also read a few similar questions on this board with generic solutions that I wasn't able to use. I am familiar with Calc and BASIC, but a beginner regarding OpenOffice macros, although I have been able to write/record simple ones, or adapt some of the ones published on this site. I hope someone can help me with something concrete.
When I try to record a macro to create a DataPilot table, this is what I get:
Code: Select all
sub Pivot
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 = "$A$1:$C$30"
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args1())
rem ----------------------------------------------------------------------
rem dispatcher.executeDispatch(document, ".uno:DataDataPilotRun", "", 0, Array())
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:DataPilotExec", "", 0, Array())
end sub
It doesn't work, and I understand that the macro recorder has limited functionality.
Regarding the solution in this post, I may need some help about how to apply it. I added the line:
Code: Select all
oDescriptor = oSheetObj.DatapilotTables.createDataPilotDescriptor()
at the beginning of the script.
So, my macro now looks like this:
Code: Select all
sub Pivot
rem -------------------------
rem Added following line per http://user.services.openoffice.org/en/forum/viewtopic.php?f=20&t=13598
oDescriptor = oSheetObj.DatapilotTables.createDataPilotDescriptor()
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 = "$A$1:$C$30"
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args1())
rem ----------------------------------------------------------------------
rem dispatcher.executeDispatch(document, ".uno:DataDataPilotRun", "", 0, Array())
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:DataPilotExec", "", 0, Array())
end sub
It still doesn work. I get the following error: "BASIC runtime error. Object variable not set."
I may be missing something simple.
I also tried the example from
http://wiki.services.openoffice.org/wik ... ilot_Table
This script is apparently not based on BASIC syntax, and I was not able to run it . The // for comments, and semi-colons at the end of the lines were rejected, and it was choking on a line like:
Code: Select all
com.sun.star.sheet.XDataPilotTablesSupplier xDPSupp = (com.sun.star.sheet.XDataPilotTablesSupplier)
I would appreciate any help. Many thanks.