Home |
Search |
Today's Posts |
#11
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I haven't read all this discussion but propbably easier to have just the one
macro Sub MyProc() Dim shp As Shape Dim s As String, n As Long s = Application.Caller ' assuming names like "Line x" n = Val(Mid$(s, 5, 5)) Set shp = ActiveSheet.Shapes(Application.Caller) Stop 'press Alt-v, s 'Look "shp" in Locals for properties that can be returned 'maybe 'Select case n ' etc End Sub Sub setup() Dim oLine As Line For Each oLine In ActiveSheet.Lines oLine.OnAction = "myProc" Next End Sub Regards, Peter T "avveerkar" wrote in message ... 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 |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
OnAction events intermittently failing on Shapes in Dialogsheets | Excel Discussion (Misc queries) | |||
Shapes and Events and Custom Menue | Excel Programming | |||
XL2000: Shape object events | Excel Programming | |||
Events on shapes | Excel Programming | |||
trapping click events on shapes | Excel Programming |