Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
In Excel 2003, I've created a userform. Then through macros, I add
commandbuttons. I've already added in the Userform code (using the editor) which should execute when the buttons are clicked. (There's one subroutine for each button, e.g.: Private Sub CommandButton1_Clicked() Call Bclicked(1) End Sub The problem is, when I click on the commandbuttons generated by the macro, the none of the subroutines execute. (I do have two commandbuttons that are predefined, and they work fine.) Any suggestions why this might be happening? Thanks |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Get to the Immediate Window within your VBE
and type Application.EnableEvents = True << and press the Enter Key "Bert" wrote: In Excel 2003, I've created a userform. Then through macros, I add commandbuttons. I've already added in the Userform code (using the editor) which should execute when the buttons are clicked. (There's one subroutine for each button, e.g.: Private Sub CommandButton1_Clicked() Call Bclicked(1) End Sub The problem is, when I click on the commandbuttons generated by the macro, the none of the subroutines execute. (I do have two commandbuttons that are predefined, and they work fine.) Any suggestions why this might be happening? Thanks |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
If it is written as posted it won't fire because the sytax is in error.
Private Sub CommandButton1_Clicked() <<<This is in error Call Bclicked(1) End Sub Correct syntax is Private Sub CommandButton1_Click() The macro call for Bclicked correctly has an argument in parentheses but is the argument valid? If the argument is not valid then that macro will not run and you should be getting an error message. "Bert" wrote: In Excel 2003, I've created a userform. Then through macros, I add commandbuttons. I've already added in the Userform code (using the editor) which should execute when the buttons are clicked. (There's one subroutine for each button, e.g.: Private Sub CommandButton1_Clicked() Call Bclicked(1) End Sub The problem is, when I click on the commandbuttons generated by the macro, the none of the subroutines execute. (I do have two commandbuttons that are predefined, and they work fine.) Any suggestions why this might be happening? Thanks |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You're right. In the code, it's actually as you have it corrected.
....still won't run, though. "JLGWhiz" wrote in message ... If it is written as posted it won't fire because the sytax is in error. Private Sub CommandButton1_Clicked() <<<This is in error Call Bclicked(1) End Sub Correct syntax is Private Sub CommandButton1_Click() The macro call for Bclicked correctly has an argument in parentheses but is the argument valid? If the argument is not valid then that macro will not run and you should be getting an error message. "Bert" wrote: In Excel 2003, I've created a userform. Then through macros, I add commandbuttons. I've already added in the Userform code (using the editor) which should execute when the buttons are clicked. (There's one subroutine for each button, e.g.: Private Sub CommandButton1_Clicked() Call Bclicked(1) End Sub The problem is, when I click on the commandbuttons generated by the macro, the none of the subroutines execute. (I do have two commandbuttons that are predefined, and they work fine.) Any suggestions why this might be happening? Thanks |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
It might help to post the code that creates the buttons, plus the click event
code behind the buttons that don't fire. Otherwise, we are whistling in the wind here. "Bert" wrote: You're right. In the code, it's actually as you have it corrected. ....still won't run, though. "JLGWhiz" wrote in message ... If it is written as posted it won't fire because the sytax is in error. Private Sub CommandButton1_Clicked() <<<This is in error Call Bclicked(1) End Sub Correct syntax is Private Sub CommandButton1_Click() The macro call for Bclicked correctly has an argument in parentheses but is the argument valid? If the argument is not valid then that macro will not run and you should be getting an error message. "Bert" wrote: In Excel 2003, I've created a userform. Then through macros, I add commandbuttons. I've already added in the Userform code (using the editor) which should execute when the buttons are clicked. (There's one subroutine for each button, e.g.: Private Sub CommandButton1_Clicked() Call Bclicked(1) End Sub The problem is, when I click on the commandbuttons generated by the macro, the none of the subroutines execute. (I do have two commandbuttons that are predefined, and they work fine.) Any suggestions why this might be happening? Thanks |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Here's the code that the click event should activate:
Private Sub CommandButton1_Click() Call BClicked(1) End Sub Private Sub CommandButton2_Click() Call BClicked(2) End Sub ....and so on. A minimum of 20 buttons, possibly as many as 40. Here's the code that creates rows and columns of buttons: Sub Add_Buttons2(aRows, aCols) bHeight = 42 bWidth = 42 VOffset = bHeight + 3 HOffset = bWidth + 3 StartLeft = (-1 * HOffset) + 2 StartTop = (-1 * VOffset) + 40 a = 1 w = (aCols * (HOffset + 1.3)) If w < 278 Then ' make sure the form is wider than label1 and the two predefined buttons w = 278 HOffset = (278 / aCols) - 2 StartLeft = StartLeft - 2 End If UserForm4.Width = w UserForm4.Height = (aRows * (VOffset + 6.4)) + 38 ' the 38 accounts for the yes/no prompt at top of form Dim myUF As UserForm Set myUF = UserForm4 Dim myBtn As Control For b = 1 To aRows ' CurTop = StartTop + (VOffset * b) For c = 1 To aCols Set myBtn = UserForm4.Controls.Add("Forms.CommandButton.1") With myBtn .Left = StartLeft + (HOffset * c) .Top = CurTop .Width = bWidth .Height = bHeight .FontSize = 26 .Caption = a End With Call Add_Code(Trim$(Str$(a))) If a = TotalItems Then Exit Sub End If a = a + 1 Next c Next b End Sub "JLGWhiz" wrote in message ... It might help to post the code that creates the buttons, plus the click event code behind the buttons that don't fire. Otherwise, we are whistling in the wind here. "Bert" wrote: You're right. In the code, it's actually as you have it corrected. ....still won't run, though. "JLGWhiz" wrote in message ... If it is written as posted it won't fire because the sytax is in error. Private Sub CommandButton1_Clicked() <<<This is in error Call Bclicked(1) End Sub Correct syntax is Private Sub CommandButton1_Click() The macro call for Bclicked correctly has an argument in parentheses but is the argument valid? If the argument is not valid then that macro will not run and you should be getting an error message. "Bert" wrote: In Excel 2003, I've created a userform. Then through macros, I add commandbuttons. I've already added in the Userform code (using the editor) which should execute when the buttons are clicked. (There's one subroutine for each button, e.g.: Private Sub CommandButton1_Clicked() Call Bclicked(1) End Sub The problem is, when I click on the commandbuttons generated by the macro, the none of the subroutines execute. (I do have two commandbuttons that are predefined, and they work fine.) Any suggestions why this might be happening? Thanks |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I don't know why it's happening, but as an alternative...
How about adding all the commandbuttons you need, but hide the ones you don't need until later. I've always found making something visible is a lot easier to do. Bert wrote: In Excel 2003, I've created a userform. Then through macros, I add commandbuttons. I've already added in the Userform code (using the editor) which should execute when the buttons are clicked. (There's one subroutine for each button, e.g.: Private Sub CommandButton1_Clicked() Call Bclicked(1) End Sub The problem is, when I click on the commandbuttons generated by the macro, the none of the subroutines execute. (I do have two commandbuttons that are predefined, and they work fine.) Any suggestions why this might be happening? Thanks -- Dave Peterson |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Interesting suggestion. If I make the buttons invisible, can I resize the
Userform to so that I don't have half of it seem empty? "Dave Peterson" wrote in message ... I don't know why it's happening, but as an alternative... How about adding all the commandbuttons you need, but hide the ones you don't need until later. I've always found making something visible is a lot easier to do. Bert wrote: In Excel 2003, I've created a userform. Then through macros, I add commandbuttons. I've already added in the Userform code (using the editor) which should execute when the buttons are clicked. (There's one subroutine for each button, e.g.: Private Sub CommandButton1_Clicked() Call Bclicked(1) End Sub The problem is, when I click on the commandbuttons generated by the macro, the none of the subroutines execute. (I do have two commandbuttons that are predefined, and they work fine.) Any suggestions why this might be happening? Thanks -- Dave Peterson |
#9
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Bert,
============= Dave Peterson: I don't know why it's happening, but as an alternative... How about adding all the commandbuttons you need, but hide the ones you don't need until later. I've always found making something visible is a lot easier to do. Interesting suggestion. If I make the buttons invisible, can I resize the Userform to so that I don't have half of it seem empty? ============= As a schematic example. consider: '========= Option Explicit '------------- Private Sub UserForm_Initialize() With Me .Height = 130 .CommandButton1.Visible = False .CommandButton2.Visible = False End With End Sub '------------- Sub CommandButton1_Click() MsgBox "Hi from CommmandButton1" End Sub '------------- Sub CommandButton2_Click() MsgBox "Hi from CommmandButton2" End Sub '------------- Private Sub CommandButton3_Click() With Me .CommandButton1.Visible = True .CommandButton2.Visible = True .Height = .Height + .CommandButton1.Height + 10 End With End Sub '<<========= --- Regards. Norman |
#10
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Your suggestion seems like a simple, straightforward solution.
Thanks. "Norman Jones" wrote in message ... Hi Bert, ============= Dave Peterson: I don't know why it's happening, but as an alternative... How about adding all the commandbuttons you need, but hide the ones you don't need until later. I've always found making something visible is a lot easier to do. Interesting suggestion. If I make the buttons invisible, can I resize the Userform to so that I don't have half of it seem empty? ============= As a schematic example. consider: '========= Option Explicit '------------- Private Sub UserForm_Initialize() With Me .Height = 130 .CommandButton1.Visible = False .CommandButton2.Visible = False End With End Sub '------------- Sub CommandButton1_Click() MsgBox "Hi from CommmandButton1" End Sub '------------- Sub CommandButton2_Click() MsgBox "Hi from CommmandButton2" End Sub '------------- Private Sub CommandButton3_Click() With Me .CommandButton1.Visible = True .CommandButton2.Visible = True .Height = .Height + .CommandButton1.Height + 10 End With End Sub '<<========= --- Regards. Norman |
#11
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Bert,
Your suggestion seems like a simple, straightforward solution. Thanks In fact the suggestion was made by Dave and, therefore, the thanks are due to him. --- Regards. Norman "Bert" wrote in message news:ZJ7Tj.971$k11.671@trndny08... Your suggestion seems like a simple, straightforward solution. Thanks. "Norman Jones" wrote in message ... Hi Bert, ============= Dave Peterson: I don't know why it's happening, but as an alternative... How about adding all the commandbuttons you need, but hide the ones you don't need until later. I've always found making something visible is a lot easier to do. Interesting suggestion. If I make the buttons invisible, can I resize the Userform to so that I don't have half of it seem empty? ============= As a schematic example. consider: '========= Option Explicit '------------- Private Sub UserForm_Initialize() With Me .Height = 130 .CommandButton1.Visible = False .CommandButton2.Visible = False End With End Sub '------------- Sub CommandButton1_Click() MsgBox "Hi from CommmandButton1" End Sub '------------- Sub CommandButton2_Click() MsgBox "Hi from CommmandButton2" End Sub '------------- Private Sub CommandButton3_Click() With Me .CommandButton1.Visible = True .CommandButton2.Visible = True .Height = .Height + .CommandButton1.Height + 10 End With End Sub '<<========= --- Regards. Norman |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Trigger or code | Excel Discussion (Misc queries) | |||
How to stop CommandButtons being deleted as pictures in code?? | Excel Programming | |||
Trigger Event Code | Excel Programming | |||
Trigger code | Excel Programming |