Well, in this case, the shape object in question is not merely a shape,
instead an OLE Object (Image Control) is contained in it. The OLE Object
(Forms Image Control) exposes its own events. One way (weird one)  is to
duplicate the Image1 shape on Click and in the Click Event handler
programmatically add an even handler (in the Sheets' CodeModule) for the new
shape. And that requires to Set The Trust Programmatic Access To VBA IDE in
the Macro Security Options.

Regards

Ajit


-----Original Message-----
From: excel-macros@googlegroups.com [mailto:excel-mac...@googlegroups.com]
On Behalf Of Adrian
Sent: Wednesday, July 22, 2009 2:53 AM
To: MS EXCEL AND VBA MACROS
Subject: $$Excel-Macros$$ Problem with duplicating a Shape and defining
OnAction property


Hello all,

I was wondering if anyone could tell me why, when I Duplicate a Shape
(image), I can't assign OnAction property to it. Following is a simple
code that gives me "Run-time error 1004: Application-defined or object-
defined error":

Sub Image1_Click()
    Dim new_shape As Excel.Shape
    Set new_shape = ThisWorkbook.Sheets("Sheet1").Shapes
("Image1").Duplicate
    new_shape.OnAction = "exclamation"
End Sub

Private Sub exclamation()
   MsgBox "!"
End Sub

Following is xls with the code set up:

http://groups.google.com/group/excel-macros/web/OnAction_problem.xls?hl=en

I also noticed that when I create a new Shape in VBA, then I can
assign OnAction to it. However, since creating a new image requires
thea path of the image on the local drive, I want to duplicate it from
the spreadsheet instead.

Thank you in advance,




--~--~---------~--~----~------------~-------~--~----~
----------------------------------------------------------------------------------
Some important links for excel users:
1. Excel and VBA Tutorials(Video and Text), Free add-ins downloads at 
http://www.excelitems.com
2. Excel tutorials at http://www.excel-macros.blogspot.com
3. Learn VBA Macros at http://www.vbamacros.blogspot.com
4. Excel Tips and Tricks at http://exceldailytip.blogspot.com
 

To post to this group, send email to excel-macros@googlegroups.com
If you find any spam message in the group, please send an email to:
Ayush Jain  @ jainayus...@gmail.com or
Ashish Jain @ 26may.1...@gmail.com
<><><><><><><><><><><><><><><><><><><><><><>
HELP US GROW !!

We reach over 5,000 subscribers worldwide and receive many nice notes about the 
learning and support from the group. Our goal is to have 10,000 subscribers by 
the end of 2009. Let friends and co-workers know they can subscribe to group at 
http://groups.google.com/group/excel-macros/subscribe
-~----------~----~----~----~------~----~------~--~---

Reply via email to