| View previous topic :: View next topic |
| Author |
Message |
rolandpish General User

Joined: 19 Aug 2010 Posts: 5
|
Posted: Fri Feb 25, 2011 8:00 am Post subject: How to pass a parameter to a very simple macro |
|
|
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 |
|
 |
Robert Tucker Moderator


Joined: 16 Aug 2004 Posts: 3367 Location: Manchester UK
|
Posted: Fri Feb 25, 2011 12:27 pm Post subject: |
|
|
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. _________________ LibreOffice 3.6.6 on Fedora 18, LibreOffice 4.0.2 on Ubuntu 13.04 (Double Boot) |
|
| Back to top |
|
 |
rolandpish General User

Joined: 19 Aug 2010 Posts: 5
|
Posted: Fri Feb 25, 2011 12:40 pm Post subject: |
|
|
Thanks a lot Robert.
That's exactly what I was looking for.
Kind regards. |
|
| Back to top |
|
 |
|