Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default commandbuttons won't trigger code.

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 477
Default commandbuttons won't trigger code.

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default commandbuttons won't trigger code.

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default commandbuttons won't trigger code.

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
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default commandbuttons won't trigger code.

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





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default commandbuttons won't trigger code.

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 421
Default commandbuttons won't trigger code.

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

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default commandbuttons won't trigger code.

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






  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default commandbuttons won't trigger code.

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









  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default commandbuttons won't trigger code.

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 421
Default commandbuttons won't trigger code.

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trigger or code Curt Excel Discussion (Misc queries) 0 April 20th 07 03:32 PM
How to stop CommandButtons being deleted as pictures in code?? Corey Excel Programming 5 August 15th 06 12:18 PM
Trigger Event Code Shawn Excel Programming 2 July 14th 05 02:33 PM
Trigger code Bourbon[_21_] Excel Programming 5 January 26th 04 04:06 PM


All times are GMT +1. The time now is 02:13 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"