How to Assign Worksheet Module to a Shape

K

K

Hi all, I have macro in Worksheet Module (see below)

Private Sub dd()
ActiveSheet.Range("A1").Value = "OK"
End Sub

I have a Rectangle Shape on my sheet to which I gave the name "shp".
I want to assign above macro to this shap by another macro and this
macro I want to put in normal Module.
The only problem is that I don’t want other macro which I'll put in
normal Module to be like this (see below)

Sub attch_maro()
ActiveSheet.Shapes("shp").Select
Selection.OnAction = "Sheet1.dd"
End Sub

I want other macro to be like this (see below)

Sub attch_maro()
ActiveSheet.Shapes("shp").Select
Selection.OnAction = ActiveSheet.dd
End Sub

I tried this but for some reason I am getting error and it
highlighting this line "Selection.OnAction = ActiveSheet.dd".
Basically I want to assign activesheet macro to my shape. I hope I
was able to explain my problem. Please can any friend can help
 
S

scattered

Hi all,  I have macro in Worksheet Module (see below)

Private Sub dd()
ActiveSheet.Range("A1").Value = "OK"
End Sub

I have a Rectangle Shape on my sheet to which I gave the name "shp".
I want to assign above macro to this shap by another macro and this
macro I want to put in normal Module.
The only problem is that I don’t want other macro which I'll put in
normal Module to be like this (see below)

Sub attch_maro()
ActiveSheet.Shapes("shp").Select
Selection.OnAction = "Sheet1.dd"
End Sub

I want other macro to be like this (see below)

Sub attch_maro()
ActiveSheet.Shapes("shp").Select
Selection.OnAction = ActiveSheet.dd
End Sub

I tried this but for some reason I am getting error and it
highlighting this line "Selection.OnAction = ActiveSheet.dd".
Basically I want to assign activesheet macro to my shape.  I hope I
was able to explain my problem.  Please can any friend can help

Maybe something like:

Selection.OnAction = ActiveSheet.Name & ".dd"

hth

-scattered
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top