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

How to pass a parameter to a very simple macro

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
rolandpish
General User
General User


Joined: 19 Aug 2010
Posts: 5

PostPosted: Fri Feb 25, 2011 8:00 am    Post subject: How to pass a parameter to a very simple macro Reply with quote

Hi there.

I'm creating a very simple macro for OpenCalc, here's the code:

Code:
Sub changeValue(a As String)
   Dim sheet, cell

   sheet = thisComponent.Sheets(0)
   cell = sheet.getCellRangeByName("A1")
   cell.String = a
End Sub


As you can see, it's very simple, it just changes the value of cell A1 with the one provided in the argument.
If I try to run the macro, in the Run Dialog I can choose this "changeValue" macro, but there's no option to specify the parameter. And if I try to run it, an error message appears: "Wrong number of parameters".

Where and how can I specify the parameter when executing the macro in OpenCalc?

Thanks in advance.
Back to top
View user's profile Send private message
Robert Tucker
Moderator
Moderator


Joined: 16 Aug 2004
Posts: 3407
Location: Manchester UK

PostPosted: Fri Feb 25, 2011 12:27 pm    Post subject: Reply with quote

This puts a text string in C1 into A1:
Code:

Sub SetString
Dim sheet, cell
Dim a as string
sheet = thisComponent.Sheets(0)
cell = sheet.getCellRangeByName("C1")
a = cell.String
changeValue (a)
End Sub

Sub changeValue(a As String)
   Dim sheet, cell

   sheet = thisComponent.Sheets(0)
   cell = sheet.getCellRangeByName("A1")
   cell.String = a
End Sub


This will let you type in a text string and enter it in C1 and A1:

Code:
Sub SetString
Dim sheet, cell
Dim a as string
sheet = thisComponent.Sheets(0)
cell = sheet.getCellRangeByName("C1")
cell.String = InputBox("Enter text:")
a = cell.String
changeValue (a)
End Sub

Sub changeValue(a As String)
   Dim sheet, cell

   sheet = thisComponent.Sheets(0)
   cell = sheet.getCellRangeByName("A1")
   cell.String = a
End Sub

Note that in both cases you need to run SetString.
_________________
OpenOffice 4.0.0 and LibreOffice 4.x.x on Fedora 20, Ubuntu 13.10, Windows 8.1 Preview (Triple Boot)
Back to top
View user's profile Send private message
rolandpish
General User
General User


Joined: 19 Aug 2010
Posts: 5

PostPosted: Fri Feb 25, 2011 12:40 pm    Post subject: Reply with quote

Thanks a lot Robert.

That's exactly what I was looking for.

Kind regards.
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 Macros and API 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