Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.misc,microsoft.public.excel.programming
|
|||
|
|||
![]()
What version of excel are you using?
-- Regards, Tom Ogilvy "Tina" wrote in message om... Hi, I am running the following code and Excel crashes after making the first or the second button. It also opens the code window that i dont want it to show. What should i do? Why is excel crashing? ----------------------- Workbooks("Game").Sheets("Data").Activate Dim OLEObj As OLEObject For i = 0 To 4 Set OLEObj = ActiveSheet.OLEObjects.Add(ClassType:="Forms.Comma ndButton.1", Link:=False _ , DisplayAsIcon:=False, Left:=50 + i * 100, Top:=10, Width:=80, Height:= _ 25) OLEObj.name = "TheButton" & i ' ' Create the event procedure ' With ActiveWorkbook.VBProject.VBComponents(OLEObj.Paren t.CodeName).CodeModule .InsertLines .CreateEventProc("Click", OLEObj.name) + 1, "Msgbox ""You Clicked The Button"" " End With Next i ---------------- TIA! Tina |
#2
![]()
Posted to microsoft.public.excel.misc,microsoft.public.excel.programming
|
|||
|
|||
![]()
Well, "just as described" doesn't necessarily mean a run time error. Many
times a Crash means a GPF - I was working with the original post last night and got a general protection fault when I put the loop back in. That was in xl97 also. It isn't the first time I have had a GPF using a createproc method. Anyway, reference your error - that is supposed to be the advantage of using CreateProc - it adds the correct arguments. I would use a button from the forms toolbar if I had to add them dynamically - wouldn't encounter this problem and the code could already be in the module. If the requirement is to always add five buttons and I wanted to use the ActiveX buttons, I think i would put them in place manually. -- Regards, Tom Ogilvy "Wild Bill" wrote in message ... Tom, I reproduce the error, just as described, on XL97. I used a blank workbork,inserted a userform, and stuck that code on click event, only commenting the Activate statement. The code window activates with an error msgbox "Run-time error '57017': Event handler is invalid" The 4 buttons are Continue, End, Debug, Help, unusual in that continue and debug are disabled. If you end nothing is highlighted. Help there gives ---------------------------------------------------------------------- The parameter list of an event-handling procedure must precisely match the declaration of the event. This error has the following cause and solution: . Your event-handling procedure has the wrong number of parameters. Eliminate extra parameters or add the missing ones. · One or more of your event-handling procedure parameters has the wrong data type. Make the parameter types match those of the event declaration. · Your event-handling procedure is a Function rather than a Sub. Make your procedure a Sub. An event handler can't return a value. · Another type library uses the event name for a type of its own. Qualify the name with the name of the proper type library to avoid the ambiguity. For additional information, select the item in question and press F1. ---------------------------------------------------------------------- If you try to walk the code you're victimized by http://support.microsoft.com/default...b;en-us;155051 but with the exception that you can not 'Continue' - you can only End. On Mon, 25 Aug 2003 07:58:32 -0400, "Tom Ogilvy" wrote: What version of excel are you using? |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Tom,
Thanks for your suggestion. My limitation is that I "have" to put the buttons dynamically. I was just wondering what is the difference between adding a button from the form toolbar and the way i have done it. Can you give me the code snippet for the same. Thanks! Tina *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Turn on the macro recorder and add it manually - that will give you a
specific code example. You then can assign any existing macro to the button using its onaction property. You can assign multiple buttons to the same macro and use application.Caller to determine which button fired it - application.Caller returns the name of the button. Private Sub Button_Click() dim btn as Button set btn = Activesheet.Buttons(Application.Caller) msgbox btn.Caption End Sub as an example. -- Regards, Tom Ogilvy "tina salgia" wrote in message ... Hi Tom, Thanks for your suggestion. My limitation is that I "have" to put the buttons dynamically. I was just wondering what is the difference between adding a button from the form toolbar and the way i have done it. Can you give me the code snippet for the same. Thanks! Tina *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Just to add, the code for buttons from the forms toolbar go in general
modules, not in the modules associated with worksheets, the thisworkbook or userforms. -- Regards, Tom Ogilvy "tina salgia" wrote in message ... Hi Tom, Thanks for your suggestion. My limitation is that I "have" to put the buttons dynamically. I was just wondering what is the difference between adding a button from the form toolbar and the way i have done it. Can you give me the code snippet for the same. Thanks! Tina *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Excel crashes | Setting up and Configuration of Excel | |||
Excel 2007 Crashes Whenever Add-In Button is Clicked | Setting up and Configuration of Excel | |||
excel crashes | Excel Discussion (Misc queries) | |||
Excel XP Crashes | Excel Discussion (Misc queries) | |||
Excel Crashes | Excel Discussion (Misc queries) |