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

Joined: 08 Mar 2012 Posts: 9
|
Posted: Thu Mar 08, 2012 1:27 pm Post subject: (SOLVED) paste value from active cell to a text box? |
|
|
Pretty simple, I would think, but I am more familiar with VBA, so maybe this just can't be done.
My end goal is this: Select (with the cursor/mouse) a cell with a string in it. Press a button with a macro in it which causes the string value in the cell to be pasted into the text box that I have created on the same spreadsheet. Recording the macro works for the copy portion, but not the paste portion. I can use it to copy and paste a named cell (like "A1") but don't see how to:
1. reference the ACTIVECELL
and
2. paste into the text box (seems I can't use getDrawPage in calc, right?)
using OOo 3.3 on windows xp.
Thanks in advance for any insights or work around suggestions. Please keep in mind that I am pretty confused. The more you can spell things out for me, the better, but I know you all have lives outside of answering forum posts
Moderation probe1: moved to MACROS AND API section, where all macro related questions belong to; edited subject
Last edited by ultine on Fri Mar 09, 2012 11:43 am; edited 1 time in total |
|
| Back to top |
|
 |
ken johnson Super User

Joined: 23 Apr 2009 Posts: 1851 Location: Sydney, Australia
|
Posted: Thu Mar 08, 2012 8:45 pm Post subject: |
|
|
I'm very new when it comes to OOo Basic, but this seems to work...
| Code: | Sub Main
Dim oDoc As Object
Dim oSheet As Object
oDoc = ThisComponent
oSheet = oDoc.Sheets(0)
oSheet.DrawPage(1).String = oDoc.CurrentSelection.String
End Sub | Note that the textbox is actually the second DrawPage on oSheet, the first one, a chart that just happened to be on oSheet is DrawPage(0).
Of course an error occurs when the CurrentSelection is not a cell or more than one cell.
Ken Johnson _________________ If your problem has been solved please add "[Solved]" to the beginning of your first post title (edit button). |
|
| Back to top |
|
 |
ultine General User

Joined: 08 Mar 2012 Posts: 9
|
Posted: Fri Mar 09, 2012 5:27 am Post subject: |
|
|
Can't wait to try it! Thanks for the speedy reply, Ken!
The code looks pretty good, and it avoids the getDrawPage that all of the other help topics I kept running across had, so I'm hopeful. Should get to it later today or tomorrow. Will let you all know if it works for me. |
|
| Back to top |
|
 |
ultine General User

Joined: 08 Mar 2012 Posts: 9
|
Posted: Fri Mar 09, 2012 6:31 am Post subject: |
|
|
Ken, I just tried that code with a brand new spreadsheet. As expected, there was an error until I changed the oSheet.DrawPage(1) to a (0). But now, instead of an error. Nothing happens at all. I first tried starting the macro through the library, then by creating a button with your macro assigned to it... neither one seems to do anything.
| Code: | Sub pasteTrial
Dim oDoc As Object
Dim oSheet As Object
oDoc = ThisComponent
oSheet = oDoc.Sheets(0)
oSheet.DrawPage(0).String = oDoc.CurrentSelection.String
print oDoc.CurrentSelection.String
End Sub |
When I do this, the print box does show the highlighted cell's contents. So I think the problem is in the method we are using to get that string into the text box.
Any other ideas? Was it working for you?
Thanks in advance!
-Neal |
|
| Back to top |
|
 |
JohnV Administrator

Joined: 07 Mar 2003 Posts: 8980 Location: Lexinton, Kentucky, USA
|
Posted: Fri Mar 09, 2012 8:23 am Post subject: |
|
|
| Code: | Sub Main
oDoc = ThisComponent
oSheet = oDoc.Sheets(0)
oSheet.DrawPage(0).getControl.String = oDoc.CurrentSelection.String
End Sub |
|
|
| Back to top |
|
 |
ultine General User

Joined: 08 Mar 2012 Posts: 9
|
Posted: Fri Mar 09, 2012 11:36 am Post subject: SOLVED |
|
|
Wow guys, perfect! Thanks John that did the trick. Here is my final code for anyone interested.
I added a bit that lets me keep adding items to the text box as a boiler plate so I can then manually copy and paste the list on another sheet. Not super graceful, but it gets the job done
| Code: | Sub Main
oDoc = ThisComponent
oSheet = oDoc.Sheets(0)
oSheet.DrawPage(0).getControl.String = oSheet.DrawPage(0).getControl.String & oDoc.CurrentSelection.String & "; "
End Sub |
Cheers guys |
|
| Back to top |
|
 |
|