OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Running Macros in Calc

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Calc
View previous topic :: View next topic  
Author Message
barryc
General User
General User


Joined: 26 Jul 2006
Posts: 8
Location: Ottawa, Canada

PostPosted: Mon Sep 25, 2006 8:15 am    Post subject: Running Macros in Calc Reply with quote

I recorded a macro, and it performed the desired result while recording. However, if I run it again, it does nothing. This is after installing Java JRE, as prompted.

Do macros simply not work, or am I doing something wrong?

To clarify: I started with the assumption that I did not need to write or understand any language for this task - I expected it to record my keystrokes and mouse clicks, as Excel does. However, in troubleshooting, I looked at the program (it got written in OO Basic, as it turns out). It appears that there is not enough information in the recorded macro to represent all the keystrokes I made (unless it stored this elsewhere?).

Here are the macros:
REM ***** BASIC *****

Sub Main

End Sub


sub Analysis
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 ----------------------------------------------------------------------
rem dispatcher.executeDispatch(document, ".uno:DataFilterSpecialFilter", "", 0, Array())

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

rem ----------------------------------------------------------------------
dim args3(0) as new com.sun.star.beans.PropertyValue
args3(0).Name = "aExtraHeight"
args3(0).Value = 0

dispatcher.executeDispatch(document, ".uno:SetOptimalRowHeight", "", 0, args3())


end sub


sub Anal1
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 ----------------------------------------------------------------------
rem dispatcher.executeDispatch(document, ".uno:DataFilterSpecialFilter", "", 0, Array())

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


end sub


sub HWTest
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 ----------------------------------------------------------------------
rem dispatcher.executeDispatch(document, ".uno:DataFilterSpecialFilter", "", 0, Array())

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

rem ----------------------------------------------------------------------
dim args3(0) as new com.sun.star.beans.PropertyValue
args3(0).Name = "aExtraHeight"
args3(0).Value = 0

dispatcher.executeDispatch(document, ".uno:SetOptimalRowHeight", "", 0, args3())


end sub



sub Anal2
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 ----------------------------------------------------------------------
rem dispatcher.executeDispatch(document, ".uno:DataFilterSpecialFilter", "", 0, Array())

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

rem ----------------------------------------------------------------------
dim args3(0) as new com.sun.star.beans.PropertyValue
args3(0).Name = "aExtraHeight"
args3(0).Value = 0

dispatcher.executeDispatch(document, ".uno:SetOptimalRowHeight", "", 0, args3())

rem ----------------------------------------------------------------------
dim args4(0) as new com.sun.star.beans.PropertyValue
args4(0).Name = "Sel"
args4(0).Value = false

dispatcher.executeDispatch(document, ".uno:GoToStart", "", 0, args4())


end sub

It has placed all my experimental macros in this one module.
An example in the above is Anal2, a macro to do the following:
1. Go to sheet 'All'
2. Do Data – Filter – Advanced Filter -
3. In popup window, select the desired filter criterion in left box (I selected "AnalysisCriteria").
4. Click “More”
5. Select in bottom left checkbox a range to copy the results to (I selected "Analysis")
6. This brings me to the destination sheet (called "Analysis"). Do Format – Row – Optimal Height to clean up the appearance.
7. Stop recording.

I see some of these actions (sort of) in the recorded macro, but not all, so I wonder where the rest of the macro "instructions" are.

Also, since the macro is recorded in Basic, why did it ask for JRE? I se reference to "beans", so does it need JRE even to run Basic?

I see this is the same issue as in topic 34575.
Bottom line problem: "The macro recorder records some things and not others".

Is there a solution for the non-programmer user?
Back to top
View user's profile Send private message
noranthon
Super User
Super User


Joined: 07 Jul 2005
Posts: 3318

PostPosted: Tue Sep 26, 2006 2:34 am    Post subject: Reply with quote

Hi, barryc. You have come up against a deficiency of the macro recorder. There is no solution for a non-programmer and the only one I've seen is no trivial matter.

It wasn't the macro recorder that required the JRE. It must be the tools you used which had that requirement.
_________________
search forum by month
Back to top
View user's profile Send private message
Villeroy
Super User
Super User


Joined: 04 Oct 2004
Posts: 10065
Location: Germany

PostPosted: Tue Sep 26, 2006 12:58 pm    Post subject: Reply with quote

I can provide a macro. Adjust the test-routine to your needs.
Code:

Sub test_applyAdvancedFilter()
Dim cellAddress as new com.sun.star.table.CellAddress
Dim oDBR,oCriteria
   REM set up address of target cell:
   cellAddress.Sheet = 1 'first sheet = 0
   cellAddress.Column = 0 'first = 0
   cellAddress.Row = 0 'first = 0
   REM get the address of a named range. This works with absolute refs for instance $SheetName.$A$1:$F$5
   oCriteria = thisComponent.NamedRanges.getByName("rgCriteria").getReferredCells
   oDBR = thisComponent.DatabaseRanges.getByName("Data")
   REM filter database range "Data" by oCriteria to cellAddress:
   applyAdvancedFilter thisComponent,oDBR,oCriteria,cellAddress
End Sub
REM this does not set anything but criteria and/or output-position.
REM if both are missing, the given db-range will be refreshed with current setup.
REM pass a document, a database-range, criteria-range as object and output-position as cell-address
Sub applyAdvancedFilter(oDoc,oDBRange,optional oCriteria,optional oOutputPosition)
'DESCRIPTOR
Dim oDescriptor,oNewDescriptor,bCopyOutputData as Boolean, bUseCriteria as Boolean
   oDescriptor = oDBRange.getFilterDescriptor
   bCopyOutputData = NOT isMissing(oOutputPosition)
   bUseCriteria = not isMissing(oCriteria)
   if bUseCriteria then
      oDBRange.FilterCriteriaSource = oCriteria.getRangeAddress
      oNewDescriptor = oCriteria.createFilterDescriptorByObject(oDBRange.getReferredCells)
      oDescriptor.setFilterFields(oNewDescriptor.getFilterFields)
   endif
   oDBRange.useFilterCriteriaSource = bUseCriteria
   oDescriptor.CopyOutputData = bCopyOutputData
   if bCopyOutputData then oDescriptor.OutputPosition = oOutputPosition
   oDBRange.refresh()
End Sub

There is a known bug: All criteria read from a cellrange are turned to upper case.
foo --> FOO
^Regular.Expression$ --> ^REGULAR.EXPRESSION
http://www.openoffice.org/issues/show_bug.cgi?id=63748
target: OOo3.0
_________________
Rest in peace, oooforum.org
Get help on http://forum.openoffice.org
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Calc All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group