Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Adding commandbutton at run time

I have a userform called userform1 with the code posted below in the code
module.
The userform does not contain any controls and there is nothing else in the
code module.
When I open it with "userform1.show", the commandbutton is added properly.
However, when I click on the command button, the "msgbox 7" is not
displayed.
What do I need to change to get this command button to work after I add it?
Thanks in advance for any help.
Ron


Private Sub UserForm_Initialize()
Dim cmd1 As msforms.CommandButton
Set cmd1 = UserForm1.Controls.Add("Forms.CommandButton.1")
With cmd1
.Name = "cmdOK"
.Caption = "OK"
.Font.Size = 8
.Left = 10
.Width = 40
.Top = 10
.Height = 20
End With
End Sub

Sub cmdOK_Click()
MsgBox 7
End Sub




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
Hide commandbutton? capt Excel Discussion (Misc queries) 2 February 21st 08 07:40 PM
Time log adding time from separate sheets teastman New Users to Excel 1 December 31st 05 04:14 PM
Adding time to date-time formatted cell tawtrey(remove this )@pacificfoods.com Excel Discussion (Misc queries) 4 August 12th 05 10:53 PM
Macro won't run from CommandButton Nathan Gutman Excel Programming 3 December 24th 03 07:59 PM
CommandButton.Caption Bob Phillips[_5_] Excel Programming 0 September 8th 03 08:15 AM


All times are GMT +1. The time now is 06:42 AM.

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

About Us

"It's about Microsoft Excel"