Hi all,
I'm testing parameter substitution in a SUB but am getting a partial
result only.
The original macro works well without parameter substitution being
attempted:

1. if named-range ("last_bal") exists erase it
2. if last row cell (in the balances column) is zero, go up one cell and 
    add named-range to this cell

However, when the parameter is introduced only action 1. is performed.
Would some of you be so kind to put me on the right path?
Regards,
       Ennio.
--------------------       

This is  the relevant code:

'########################################################################
public saldar
sub saldo
dim saldar  as string
' call the relevant macro
_Z_del_last_Cell("saldar")    ' using "saldar" as parameter substitution
end sub

sub _Z_del_last_Cell(last_bal As string) As String  'using last_bal as par.
' define variables
dim oDoc as object
dim dispatcher as object
' get access to the document
oDoc   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
oRanges = ThisComponent.NamedRanges
sName$=last_bal               ' "last_bal"
' ----------------------------------------------------------------------

dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "ToPoint"
args1(0).Value = "$N$5"
dispatcher.executeDispatch(oDoc,".uno:GoToCell", "", 0, args1()) 
dispatcher.executeDispatch(oDoc, ".uno:GoDownToEndOfData", "", 0, args1())

' verify if last cell's value is zero
ocell=ThisComponent.CurrentSelection
vlc = oCell.getValue()    ' get value of selected cell (last cell)
if vlc = 0 then
   ' Here we verify whether there is already a range with that name and,
   ' in the affirmative, erase it so that the new one can be created:
   If oRanges.hasByName(sName$) Then
      oRanges.getByName(sName$)
      oRanges.removeByName(sName$)
      print "deleted range: "; sName$
   End If
   dispatcher.executeDispatch(oDoc, ".uno:Cut", "", 0, args1())


   dispatcher.executeDispatch(oDoc, ".uno:GoUp", "", 0, args1())
   ocell=ThisComponent.CurrentSelection
 '  vlc = oCell.getValue()    ' get value of selected cell (last cell)
   ' we determine the row number of the selected cell: 
   ' numbering starts from 0, so we need to add 1 
    r$ = oCell.CellAddress.row+1
   xcl$ = "$N$"+r$                            'Sheet1. ref to col F may be 
changed
   print "val di xcl$: "; xcl$   
   ' we set our named range name:
   Dim oCellAddress As new com.sun.star.table.CellAddress   ' This is necessary
   oCellAddress.Sheet = 0       ' The first sheet (This is necessary)
   oRanges.addNewByName(sName$,xcl$,oCellAddress,0)     
End If

end sub

' ########################################################################

-- 
[Perche' usare Win$ozz (dico io) se ..."anche uno sciocco sa farlo.   \\?//
 Fa' qualche cosa di cui non sei capace!"  (diceva Henry Miller) ]    (°|°)
[Why use Win$ozz (I say) if ... "even a fool can do that.              )=(
 Do something you aren't good at!" (as Henry Miller used to say) ]

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

Reply via email to