Try keeping dim statements out of a loop
The macro below is similar to your macro but simplifed
This copies 1 cell moves down 1 cell & paste contents then moves to another
cell, etc.
to change increment - change args2(0).Value = 1 to "2" or "3"
The Macro Recorder ain't useless but it is dumb and prone toward safety for
beginners
Rem --------------------------------------------
sub main13
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 copy info you want--------------------------------------
dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())
rem ----define your variables ouside of
loop-------------------------------------------
dim args2(1) as new com.sun.star.beans.PropertyValue
dim num
rem ----make for-next loop
for num = 1 to 10
rem ---assign variables necessary
args2(0).Name = "By"
args2(0).Value = 1
args2(1).Name = "Sel"
args2(1).Value = false
rem ----execute arg
dispatcher.executeDispatch(document, ".uno:GoDown", "", 0, args2())
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Paste", "", 0, Array())
rem ----------------------------------------------------------------------
next num
Rem --- since outside loop force cursor to unselect last cell (note still
using arg2())
dispatcher.executeDispatch(document, ".uno:GoDown", "", 0, args2())
end sub
Rem ------------------------------
> -----Original Message-----
> From: Johnny Rosenberg [mailto:[email protected]]
> Sent: Wednesday, March 03, 2010 11:09
> To: [email protected]
> Subject: Re: [users] need help macro loop (calc 3.1)
>
> 2010/3/3 khobbos khobbos <[email protected]>:
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > Dear
> > sir
> > I
> > want to make a macro in calc 3.1
> >
> >
> >
> > Simply
> >
> >
> > I
> > wrote a formula in cell NB (A1)
> > I
> > want to jump to cell NB (A3) and paste the same
> >
> >
> >
> >
> > So I record this macro and
> > everything goes well
> > sub
> > Main13
> > 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
> >
> ----------------------------------------------------------------------
> > dispatcher.executeDispatch(document,
> > ".uno:Copy", "", 0, Array())
> > rem
> >
> ----------------------------------------------------------------------
> > dim
> > args2(1) as new com.sun.star.beans.PropertyValue
> > args2(0).Name
> > = "By"
> > args2(0).Value
> > = 1
> > args2(1).Name
> > = "Sel"
> > args2(1).Value
> > = false
> > dispatcher.executeDispatch(document,
> > ".uno:GoDown", "", 0, args2())
> > rem
> >
> ----------------------------------------------------------------------
> > dim
> > args3(1) as new com.sun.star.beans.PropertyValue
> > args3(0).Name
> > = "By"
> > args3(0).Value
> > = 1
> > args3(1).Name
> > = "Sel"
> > args3(1).Value
> > = false
> > dispatcher.executeDispatch(document,
> > ".uno:GoDown", "", 0, args3())
> > rem
> >
> ----------------------------------------------------------------------
> > dispatcher.executeDispatch(document,
> > ".uno:Paste", "", 0, Array())
> >
> > end sub
> >
> > now I need to do a loop so I can
> > for example repeat the same 10 times
> >
> > after googling I found this
> > lines
> > Dim
> > I
> > For
> > I = 1 to 10
> >
> > Inner part of loop
> > Next
> > I
> >
> > So I edit the macro in this way
> > sub
> > Main13
> > 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")
> > dim
> > i
> > for
> > i = 1 to 2
> > rem
> >
> ----------------------------------------------------------------------
> > dispatcher.executeDispatch(document,
> > ".uno:Copy", "", 0, Array())
> > rem
> >
> ----------------------------------------------------------------------
> > dim
> > args2(1) as new com.sun.star.beans.PropertyValue
> > args2(0).Name
> > = "By"
> > args2(0).Value
> > = 1
> > args2(1).Name
> > = "Sel"
> > args2(1).Value
> > = false
> > dispatcher.executeDispatch(document,
> > ".uno:GoDown", "", 0, args2())
> > rem
> >
> ----------------------------------------------------------------------
> > dim
> > args3(1) as new com.sun.star.beans.PropertyValue
> > args3(0).Name
> > = "By"
> > args3(0).Value
> > = 1
> > args3(1).Name
> > = "Sel"
> > args3(1).Value
> > = false
> > dispatcher.executeDispatch(document,
> > ".uno:GoDown", "", 0, args3())
> > rem
> >
> ----------------------------------------------------------------------
> > dispatcher.executeDispatch(document,
> > ".uno:Paste", "", 0, Array())
> > next
> > i
> >
> > end sub
> > now
> > I am getting this message : sequence element is not assignable by
> > given value!
> >
> >
> >
> >
> >
> >
> > So
> > plz can any one help me with this
> >
> >
> >
> >
> > Many
> > thanks
> >
> >
> >
> > Regards
> > _________________________________________________________________
> > Your E-mail and More On-the-Go. Get Windows Live Hotmail Free.
> > https://signup.live.com/signup.aspx?id=60969
>
> What does NB mean?
>
> I have only one advice: Never use the crappy macro recorder. It's
> quite useless. There is a slightly better one somewhere to install, if
> you like, I guess someone else can tell you exactly where to find it.
>
> Regards
>
> Johnny Rosenberg
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]