View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
avveerkar[_40_] avveerkar[_40_] is offline
external usenet poster
 
Posts: 1
Default Shapes object events?


Dr.Ile Wrote:
Thank you AVeerkar again, you show me the right way (I want to assign
different proc to individual lines - myproc1, myproc2,myproc3 etc). I
also ruminated abbout OnAction method and now I'm sure that this is it!
I have only one question:
As I already wrote, the number of lines is unknown (till the DXF is
imported) and consecutive the number of macro myproc1, myproc2,myproc3
etc. Do you suggest to write approx. 500 macros, soo last macro will be
myproc500 (I work with approx. 400 lines). With 500 macros I’ll capture
all possible lines. Is there onother way. I read that’s possible to
write I macro with VBA, but...:).

Dr.ile


Yes choose a large number ( say 500 ) to cover the actual number of
lines you may have. After the procedure assigns macro to the last line,
when it tries to assign a macro to a new line which does not exist, it
will give an error. Trap that error with On Error Exit Sub. This could
be your first line of the sub before you enter For..Next loop to assign
macros to different lines. Thus your sub would be
Sub AssgnMacro()
On Error Exit Sub
For i = 1 to 500
ActiveSheet.Shapes(i).select
Selection.OnAction ="myproc" & i
Next
End Sub

There would be error on two counts -either when it tries to assign proc
to a non-existant line or tries to assign a proccedure which does not
exist. It means that you must have enough number of procedures (
Myproc1 to Myproc500 ) to cover maximum number of lines you may
actually have. Since we are now only exiting on error, if number of
procedures is less than you actually require, the sub will just exit
without assigning any macro to last lines and there wont be any
indication.

A V Veerkar


--
avveerkar
------------------------------------------------------------------------
avveerkar's Profile: http://www.excelforum.com/member.php...o&userid=30338
View this thread: http://www.excelforum.com/showthread...hreadid=506688