ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Assigning Macro To Shape (https://www.excelbanter.com/excel-programming/281063-assigning-macro-shape.html)

Tommi[_2_]

Assigning Macro To Shape
 
Hello!
I need to make a macro that will create a new worksheet, add a Shape-object
(any one which is similar to button), then assign a macro to that Shape.

I haven't been able to do this. The problem is how to select the
Shape-object properly.

Can you help me!

BR, Tommi



Ron de Bruin

Assigning Macro To Shape
 
Try something like this
I assume that the macro exist??


Sub test()
Dim Nsheet As Worksheet
Set Nsheet = Worksheets.Add
Nsheet.Shapes.AddShape(msoShapeRectangle, 100, 200, 150, 50).Select
Selection.OnAction = "yourmacro"
Nsheet.Range("A1").Select
End Sub


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl



"Tommi" wrote in message ...
Hello!
I need to make a macro that will create a new worksheet, add a Shape-object
(any one which is similar to button), then assign a macro to that Shape.

I haven't been able to do this. The problem is how to select the
Shape-object properly.

Can you help me!

BR, Tommi





Tommi[_2_]

Assigning Macro To Shape
 
Thanks very much Ron!
The problem was not anything more than that I didn't select any range after
assigning macro to a Shape and thus it didn't work.
Now it works!

I am glad that it is possible to ask other users who know things better.

BR,
Tommi

"Ron de Bruin" wrote in message
...
Try something like this
I assume that the macro exist??


Sub test()
Dim Nsheet As Worksheet
Set Nsheet = Worksheets.Add
Nsheet.Shapes.AddShape(msoShapeRectangle, 100, 200, 150, 50).Select
Selection.OnAction = "yourmacro"
Nsheet.Range("A1").Select
End Sub


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl



"Tommi" wrote in message

...
Hello!
I need to make a macro that will create a new worksheet, add a

Shape-object
(any one which is similar to button), then assign a macro to that Shape.

I haven't been able to do this. The problem is how to select the
Shape-object properly.

Can you help me!

BR, Tommi








All times are GMT +1. The time now is 10:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com