Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Using automatically entered code

I am having some trouble inserting objects onto a form and using
automatically inserted code. I start with a blank userform. The
segment below addes an optionbuttion and writes some code to handle
clicks on it. Notice the commented out "OptionButton1_Click". Of
course, it needs to be commented out because otherwise
UserForm_Initialize() would not compile because it does not exist at
the program's start. The new sub is created ok, but when I click on
the resulting option button, nothing happens. Why not?????

Private Sub UserForm_Initialize()
Dim cntNew As MSForms.Control

Set cntNew = UserForm2.Controls.Add("Forms.OptionButton.1")
With cntNew
.Value = False
With
Application.VBE.ActiveVBProject.VBComponents("User Form2").CodeModule
.InsertLines .CountOfLines + 1, ("Sub " & cntNew.Name &
"_Click()")
.InsertLines .CountOfLines + 1, ("msgbox ""Here - New
Subroutine!!!!!""") ' tag
.InsertLines .CountOfLines + 1, ("End Sub")
End With
MsgBox .Name
' OptionButton1_Click
End With
Set cntNew = Nothing

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Using automatically entered code

In searching there is probably a way to do this but I couldn't find it. One
alternative I saw was to include the control on the userform, but set its
visible property to false until needed. Perhaps that would be easier as the
code is there from the beginning.


"Tim" wrote in message
ups.com...
I am having some trouble inserting objects onto a form and using
automatically inserted code. I start with a blank userform. The
segment below addes an optionbuttion and writes some code to handle
clicks on it. Notice the commented out "OptionButton1_Click". Of
course, it needs to be commented out because otherwise
UserForm_Initialize() would not compile because it does not exist at
the program's start. The new sub is created ok, but when I click on
the resulting option button, nothing happens. Why not?????

Private Sub UserForm_Initialize()
Dim cntNew As MSForms.Control

Set cntNew = UserForm2.Controls.Add("Forms.OptionButton.1")
With cntNew
.Value = False
With
Application.VBE.ActiveVBProject.VBComponents("User Form2").CodeModule
.InsertLines .CountOfLines + 1, ("Sub " & cntNew.Name &
"_Click()")
.InsertLines .CountOfLines + 1, ("msgbox ""Here - New
Subroutine!!!!!""") ' tag
.InsertLines .CountOfLines + 1, ("End Sub")
End With
MsgBox .Name
' OptionButton1_Click
End With
Set cntNew = Nothing

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Using automatically entered code

The problem being that I don't know how many controls will need to
exist on the form before the form needs to be loaded.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Using automatically entered code

How many variations would there be? You could have several similar userforms
with the appropriate controls, that load depending on the form needed. Or
you could change the captions on the controls programmatically to suit your
needs or a combination of both. I think it would be a lot easier to program
that way. Or you could add controls for every possibility and "grey" them
out if they are not usable.

Jon

"Tim" wrote in message
oups.com...
The problem being that I don't know how many controls will need to
exist on the form before the form needs to be loaded.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Using automatically entered code

Yea. I suppose I could try something like that. I was just hoping for
something more elegant.
Thanks much, Jon;
-Tim



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
Automatically generating a city name based on entered zip code Lycean Excel Discussion (Misc queries) 1 October 31st 09 06:28 PM
Automatically insert a new row when certain number is entered in c Question, Mark Excel Discussion (Misc queries) 1 April 4th 09 02:27 AM
Dates-Automatically entered in cells Taryn Excel Discussion (Misc queries) 8 January 31st 09 10:23 AM
Contents automatically entered into another cell a_occellaris New Users to Excel 1 July 28th 08 08:57 PM
Drop Down/List w/Code and Definition, only code entered when selec Spiritdancer Excel Worksheet Functions 2 November 2nd 07 03:57 AM


All times are GMT +1. The time now is 05:38 PM.

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"