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

(SOLVED) paste value from active cell to a text box?

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


Joined: 08 Mar 2012
Posts: 9

PostPosted: Thu Mar 08, 2012 1:27 pm    Post subject: (SOLVED) paste value from active cell to a text box? Reply with quote

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 Laughing



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
View user's profile Send private message Send e-mail
ken johnson
Super User
Super User


Joined: 23 Apr 2009
Posts: 2032
Location: Sydney, Australia

PostPosted: Thu Mar 08, 2012 8:45 pm    Post subject: Reply with quote

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
View user's profile Send private message
ultine
General User
General User


Joined: 08 Mar 2012
Posts: 9

PostPosted: Fri Mar 09, 2012 5:27 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
ultine
General User
General User


Joined: 08 Mar 2012
Posts: 9

PostPosted: Fri Mar 09, 2012 6:31 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
JohnV
Administrator
Administrator


Joined: 07 Mar 2003
Posts: 9183
Location: Lexinton, Kentucky, USA

PostPosted: Fri Mar 09, 2012 8:23 am    Post subject: Reply with quote

Code:
Sub Main
oDoc = ThisComponent
oSheet = oDoc.Sheets(0)
oSheet.DrawPage(0).getControl.String = oDoc.CurrentSelection.String
End Sub
Back to top
View user's profile Send private message
ultine
General User
General User


Joined: 08 Mar 2012
Posts: 9

PostPosted: Fri Mar 09, 2012 11:36 am    Post subject: SOLVED Reply with quote

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
View user's profile Send private message Send e-mail
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