![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
|
Hi All,
I have a number of text boxes that were created dynamically at run time. When they were created I had the background color set to red. Is there a way to have the background color yellow when the text box is being typed in and then turn green after it has been typed in. The textboxes are named mytextboxes(counter) where counter is a number from 1 to 100. The problem that I run into is that I cannot declare an on click action because the text boxes are created at run time. Any help would be greatly appreciated. |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,927
|
Well, you could take a look at this:
http://www.cpearson.com/excel/vbe.htm to know how to add code dynamically, but, I think that it could create a mess. Another option, don't know how hard it will be (I'm guessing it will be less than the first option) would be to use a class module to do that. |
|
|
|
|
|
#3 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
|
I went to the site and couldn't find the link to adding code at run time. I am not too familiar with class modules. Can you post some sample code of how I can change the background color of any textbox if the textbox has been clicked and then change it to another color once it is not active anymore? Thank you for any help you can give.
|
|
|
|
|
|
#4 |
|
Legend
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
|
It's described here by Chip:
Adding A Procedure To A Module The procedure below will add a new procedure called "MyNewProcedure" to the module named "NewModule" in ThisWorkbook. Sub AddProcedure() Dim VBCodeMod As CodeModule Dim LineNum As Long Set VBCodeMod = ThisWorkbook.VBProject.VBComponents("NewModule").CodeModule With VBCodeMod LineNum = .CountOfLines + 1 .InsertLines LineNum, _ "Sub MyNewProcedure()" & Chr(13) & _ " Msgbox ""Here is the new procedure"" " & Chr(13) & _ "End Sub" End With Application.Run "MyNewProcedure" End Sub Cheers, Nate |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|