AboutDamon Ostrander Expertise I have extensive experience with VBA programming in Excel 5 through Excel 2007. I am an consultant in a small defense technology services company, and have developed a wide range of applications in VBA, including simulations involving mixed-language programming, satellite orbit mechanics, graphics and animation, and real-time applications. I am interested in moderate to hard VBA-related questions only.
Experience I have developed and taught several courses in Excel VBA programming and also VBA programming in Office 97, 2000, and 2007. I have developed a number of large technical applications in Excel VBA for use within the aerospace industry.
Question Hello Mr Damon, I have some problem when creating a program in excel. i want to create a command button automatically when i still running a program that i've made in excel. this is the case:
when i input a data in a some text field in my program an after that i press some commandbutton, the command button will create another commandbutton in the same form with the caption value like the one i have typed at the text field before. is it possible to do that? thanks before.
Answer Hello hilman,
I am assuming all these controls are on a userform. While I believe it is possible to add a commandbutton while a form is running, it requires a lot of code to position it in the right place on the form, size it, assign it to run code, etc. I suggest an easier way.
What I would recommend is to create the new commandbutton on the form, placing it exactly where you want it to appear, sizing it, etc. Then set its Visible property to False in its property sheet. When you show the form, this button will not be visible because of this.
Once you have the (invisible) button on the form, you can use code like this in the other commandbutton's Click event code to caption it using the text in the textbox, and to make it visible:
Private Sub CommandButton2_Click()
If TextBox1.Text <> "" Then
CommandButton3.Caption = TextBox1.Text
CommandButton3.Visible = True
End If
End Sub
In this code CommandButton2 is the commandbutton that you click to make the new commandbutton (CommandButton3) appear. The code assumes a textbox name TextBox1 on the form contains the text you want to use as a caption. Note that this code does nothing unless there is some text in the textbox.
About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here