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

Getting drawing obj's text when clicked to run macro

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


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

PostPosted: Tue Apr 26, 2011 11:43 pm    Post subject: Getting drawing obj's text when clicked to run macro Reply with quote

I have a Calc sheet with 15 drawing objects.
Each one is assigned to a different macro.
The macros are all very similar, the only difference being the value of one constant.

When a macro is run is it possible to determine the text in the drawing object that was clicked to start it?
If there is a way of getting the clicked drawing object's text I could use one macro instead of 15.

Ken Johnson
Back to top
View user's profile Send private message
B Marcelly
Super User
Super User


Joined: 12 May 2004
Posts: 1453
Location: France

PostPosted: Wed Apr 27, 2011 6:48 am    Post subject: Reply with quote

Hi,
A simpler way: use a common subroutine.
Code:
Sub macro1
myBigMacro(5)
End Sub

Sub macro2
myBigMacro(78)
End Sub

Sub macro3
myBigMacro(224)
End Sub

' ------

Sub myBigMacro(v As Long)
  ' here use variable v
End Sub

_________________
Bernard

OpenOffice.org 1.1.5 fr / Apache OpenOffice 4.0.1 / LibreOffice 4.1.0
MS-Windows 7 Home SP1
This forum is spammed, use instead Apache OpenOffice forums
Back to top
View user's profile Send private message Visit poster's website
ken johnson
Super User
Super User


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

PostPosted: Wed Apr 27, 2011 7:22 am    Post subject: Reply with quote

Thanks Bernard, that is most probably the way I will do it.

Just out of interest though is it possible to get a drawing object's text after it has been clicked to run a macro (or a command button's label)?

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
B Marcelly
Super User
Super User


Joined: 12 May 2004
Posts: 1453
Location: France

PostPosted: Wed Apr 27, 2011 10:53 pm    Post subject: Reply with quote

There is no information transmitted to the macro started from a shape. I don't think it is possible to find the originating shape.

If the macro is started from a button (a form control), then you get an event object which points to the control.
_________________
Bernard

OpenOffice.org 1.1.5 fr / Apache OpenOffice 4.0.1 / LibreOffice 4.1.0
MS-Windows 7 Home SP1
This forum is spammed, use instead Apache OpenOffice forums
Back to top
View user's profile Send private message Visit poster's website
ken johnson
Super User
Super User


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

PostPosted: Wed Apr 27, 2011 11:42 pm    Post subject: Reply with quote

Thanks Bernard.

Ken Johnson
Back to top
View user's profile Send private message
tkdg
Newbie
Newbie


Joined: 06 May 2012
Posts: 1

PostPosted: Sun May 06, 2012 4:25 pm    Post subject: Reply with quote

Hi,
I'm not super familiar with OO coding - I've translated a few macros - but i have been successful with excel vba using the below... I know it might not be too helpful, but it might get you looking in a different direction.
Take it for what it's worth...
Cheers!


I've used "Application.caller" to get the name of the object calling the macro. In my example I used multiple transparent shapes with different names that had the same macro ("zoomer") assigned to them.

Once you have the name of the object then you can get the other details using the various properties. e.g. shapes(nam).TopLeftCell.Column

Code:


Sub zoomer()
nam = ActiveSheet.Shapes(Application.Caller).Name

With ActiveWindow
    If .Zoom > 75 Then
        .Zoom = 75
        .ScrollColumn = 1
        .ScrollRow = 1
   
        .Width = 1302
        .Height = 715.5
    Else
        .Zoom = 185
        .ScrollColumn = ActiveSheet.Shapes(nam).TopLeftCell.Column
        .ScrollRow = ActiveSheet.Shapes(nam).TopLeftCell.Row
    End If
End With
End Sub
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