Top posting about writing macros (original message still at bottom).

You may recall my post about the recorder and UNO Dispatch calls versus
using API calls.

I don't really like the macro recorder - it serves a very basic need
only. But given that I haven't written a better one who am I to
complain. When I record a macro I usually tidy it up using a function
that I have written. Here is that function and an example of how it
could be used:

function fnDispatch(sCommand as string, optional mArgs)
oFrame = ThisComponent.CurrentController.Frame
oDispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
'on error resume next
if isMissing(mArgs) then
        fnDispatch = oDispatcher.executeDispatch(oFrame, ".uno:" & _ sCommand,
"", 0, array())
else
        nArgs = uBound(mArgs) \ 2
        dim Args(nArgs) as new com.sun.star.beans.PropertyValue
        for i = 0 to nArgs
                Args(i).name = mArgs(i * 2)
                Args(i).value = mArgs(i * 2 + 1)
        next
        fnDispatch = oDispatcher.executeDispatch(oFrame, ".uno:" & _ sCommand,
"", 0, Args())
end if
end function


sub wtb_title_freeze
fnDispatch("GoToCell", array("ToPoint","$C$5")
fnDispatch("FreezePanes")
end sub


Now for doing the same thing using API calls:

sub wtb_title_freeze
oCurController = thisComponent.currentController
oCurController.freezeAtPosition(2, 4)
end sub

And to verify the frozen state:
if thisComponent.currentController.hasFrozenPanes then
  msgbox "Frozen"
else
  msgbox "Not frozen"
end if

I have never experienced your navigation problems.

Getting on top of writing macros in OOo is not easy. I hope to have
some, hopefully user friendly, guides done in the next month.

Some suggestions:
Download xray.xray from http://ooomacros.org/ I couldn't cope without
it.
Download the SDK - in my opinion it is hard to read and follow but it
still helps a lot!
See Andrew Pitonyak's page http://www.pitonyak.org/oo.php and his links
to other information.
The better mail list for this type of message is [email protected]
see http://api.openoffice.org/servlets/ProjectMailingListList for
subscribing etc.
I have found the OOo forums for Macros and API and Code Snippets
invaluable; see http://www.oooforum.org
There are also code snippets available from:
http://codesnippets.services.openoffice.org/

For a list of UNO dispatch calls see:
http://framework.openoffice.org/files/documents/25/1042/commands_11beta.html
There is also a file called Slots.sxw that has similar information
(search for it - I have forgotten the link).

You may find some of my work has useful bits of code to look at:
http://homepages.paradise.net.nz/hillview/OOo/

Hope this helps - Ian Laurenson

On Tue, 2005-02-22 at 10:55, Ennio-Sr wrote:
> Hi all!
> I started experimental migration of a few macros from Lotus Millennium
> to OOo and, being completely new to the OOo way of dealing with macros,
> am wondering whether it has to be so complex .-)
> 
> By way of example:
> To freeze cols and rows left and upper a certain point in a L.M.
> spreadsheet, all you have to do is:
> 
> write <~{goto}C5~/wtb~> in a cell and define a range name for it (e.g.
> <A>); then, each time you press CTRL+A you get the desired behaviour.
> Whereas in OOo it seems to be such long as this:
> 
> rem ##################################################################
> 
> sub wtb_title_freeze
> 
> 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$5" 
> dispatcher.executeDispatch(document,".uno:GoToCell", "", 0, args1()) 
> rem --------------------------------------------------------------------
> dispatcher.executeDispatch(document, ".uno:FreezePanes", "", 0,Array())
> _0_show_menu 
> 
> end sub 
> 
> rem ####################################################################
> 
> 
> I learned that clicking Windows >Freeze you can freeze/unfreeze, but
> there is no way to do that in a macro, as it doesn't appear possible to
> verify the 'frozen' status.
> 
> In L.M. you would write:
> /wtc~    # to clear the freeze
> /wtb~    # to set the freeze
> 
> In OOo, apparently, you can only do:
> 
> rem ####################################################################
> 
> sub title_freeze_unfreeze
> 
> rem --------------------------------------------------------------------
> 
> rem define variables 
> dim document   as object
> dim dispatcher as object
> 
> rem --------------------------------------------------------------------
> 
> rem get access to the documentdocument   
> =ThisComponent.CurrentController.Frame 
> dispatcher =createUnoService("com.sun.star.frame.DispatchHelper") 
> 
> rem --------------------------------------------------------------------
> 
> dispatcher.executeDispatch(document, ".uno:FreezePanes", "", 0, Array())
> 
> rem --------------------------------------------------------------------
> 
> dispatcher.executeDispatch(document, ".uno:FreezePanes", "", 0, Array())
> 
> end sub 
> 
> rem ####################################################################
> 
> without exactly knowing wheter the first .uno:FreezePanes is actually
> going to freeze or unfreeze ...
> 
> Finally (for the time being), I noticed that prior to saving any macro
> I could navigate my calc using the four arrows, pgup, pgdwn, home and
> end keys; after I saved a few macros and re-accessed the spreadsheet all
> thos keys are frozen and I can only move with the mouse.
> What have I done to get that?
> 
> Thanks for your attention.
> Regard,
>       Ennio.
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to