PC Review


Reply
Thread Tools Rate Thread

Add Button at Run-time in Code

 
 
ExcelMonkey
Guest
Posts: n/a
 
      5th Jun 2008
I am trying to add a button to a Form in code. When I run the code below the
form shows without a button on it. Why is this?

Dim NewBttn As MSForms.CommandButton

Set NewBttn = UserForm1.Controls.Add("forms.CommandButton.1")
NewBttn.Top = FirstRowSquareTop * Counter
NewBttn.Left = FirstRowSquareLeft * Counter
NewBttn.Width = FirstRowWidth * Counter
NewBttn.Visible = True
'Set NewBttn = Nothing

UserForm1.Show
End Sub
 
Reply With Quote
 
 
 
 
ExcelMonkey
Guest
Posts: n/a
 
      5th Jun 2008
Sorry this does work, my width was set incorrectly.

EM

"ExcelMonkey" wrote:

> I am trying to add a button to a Form in code. When I run the code below the
> form shows without a button on it. Why is this?
>
> Dim NewBttn As MSForms.CommandButton
>
> Set NewBttn = UserForm1.Controls.Add("forms.CommandButton.1")
> NewBttn.Top = FirstRowSquareTop * Counter
> NewBttn.Left = FirstRowSquareLeft * Counter
> NewBttn.Width = FirstRowWidth * Counter
> NewBttn.Visible = True
> 'Set NewBttn = Nothing
>
> UserForm1.Show
> End Sub

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to assign same code inside Option button code space ?? furbiuzzu Microsoft Excel Programming 1 21st Nov 2006 02:36 PM
Adding Code to Command Button Added At Run Time =?Utf-8?B?S2V2aW4gRS4=?= Microsoft Excel Programming 2 18th Oct 2006 04:11 PM
Adding Code to Command Button at Run Time =?Utf-8?B?S2V2aW4gRS4=?= Microsoft Excel Programming 1 20th Sep 2006 12:25 AM
Repost (No response last time) command button code james Microsoft Access Form Coding 2 27th Apr 2004 05:14 PM
how to know the user press the left button and the right button at the same time? vulgate Microsoft C# .NET 1 18th Nov 2003 08:21 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:31 PM.