Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Programmely written code don't work

Hi,

On a userform certain actions course extra controls AND extra event-code for
thise controls - however the code looks right........... it will not
work......

A OptionButton is created "OptionButton1" and this code is made one the
userform's code module:
Private Sub OptionButton1_Click()
MsgBox "YES"
End Sub

What do i do to make the new code work ?

Thanks,
Flemming


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Programmely written code don't work

Works for me in OfficeXP.
Are you trying to get the msgbox within the VBA window, or are you actually
bringing up the Userform in Excel and clicking the optionbutton there? Do
you have macros enabled?
Keith

"Flemming Dahl" wrote in message
...
Hi,

On a userform certain actions course extra controls AND extra event-code

for
thise controls - however the code looks right........... it will not
work......

A OptionButton is created "OptionButton1" and this code is made one the
userform's code module:
Private Sub OptionButton1_Click()
MsgBox "YES"
End Sub

What do i do to make the new code work ?

Thanks,
Flemming




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Programmely written code don't work

The code that is create in runtime is created like this:

Sub AddButtonsCode()
Dim UFvbc As Object 'VBComponent
Dim code As String
Dim n As Long
Set UFvbc = ThisWorkbook.VBProject.VBComponents("UserForm1")
For n = 1 To 10
With UFvbc.CodeModule
code = ""
code = code & "Private Sub OptionButton" & n & "_Click" & vbCr
code = code & "Msgbox ""YES - OptionButton" & n & """" & vbCr
code = code & "End Sub"
.InsertLines .CountOfLines + 1, code
End With
Next
End Sub





"Flemming Dahl" wrote in message
...
Hi,

On a userform certain actions course extra controls AND extra event-code

for
thise controls - however the code looks right........... it will not
work......

A OptionButton is created "OptionButton1" and this code is made one the
userform's code module:
Private Sub OptionButton1_Click()
MsgBox "YES"
End Sub

What do i do to make the new code work ?

Thanks,
Flemming




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Programmely written code don't work

Then you have stepped outside the bounds of my experience- I'm just starting
to figure out how to add controls at runtime in .net :-)

Just out of curiosity, have you considered the option of creating the
controls (assuming there is a limited number) and just showing/hiding (and
possibly moving) them based on the option button events?

"Flemming Dahl" wrote in message
...
Hey Keith

Looking at you answer made me think, that i have not explained my self
properly.

You see - the userform IS running, and by selection on a combobox - NEW
controls are added to the userform, and so is the event code for thise
controls. But no event takes place for the new controls.

Here a NEW control is a control that is created in runtime.

Flemming


"Keith R" wrote in message
...
Works for me in OfficeXP.
Are you trying to get the msgbox within the VBA window, or are you

actually
bringing up the Userform in Excel and clicking the optionbutton there?

Do
you have macros enabled?
Keith

"Flemming Dahl" wrote in message
...
Hi,

On a userform certain actions course extra controls AND extra

event-code
for
thise controls - however the code looks right........... it will not
work......

A OptionButton is created "OptionButton1" and this code is made one

the
userform's code module:
Private Sub OptionButton1_Click()
MsgBox "YES"
End Sub

What do i do to make the new code work ?

Thanks,
Flemming








  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Programmely written code don't work


Yes - have considered show/hide......... but that will not give the
flexibility that i need.




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Programmely written code don't work

Flemming,

That would be my approach. What flexibility does it not provide?

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Flemming Dahl" wrote in message
...

Yes - have considered show/hide......... but that will not give the
flexibility that i need.




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Programmely written code don't work


Show/Hide dos not provide the flexiblity of how many controls the user
needs.
In this case i am not going to make alle those controls and show/hide
procedures..........

Lets stop it here. It seems that you can not provide any extra information
to solve my problem.

Thanks,
Flemming


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Programmely written code don't work

Flemming,

How about a different approach, namely to create a class module that can
handle all optionbutton controls.

First, create a class module, and name it clsOpt, with this code

Public WithEvents OptButton As MSForms.OptionButton

Private Sub OptButton_Click()
'add your specific code here
MsgBox "You clicked: " & OptButton.Caption
End Sub

Then in your userform event, add this code

Dim collOpt As Collection
Dim formButton As clsOpt

Private Sub UserForm_Initialize()
Dim oCtl As MSForms.Control
Set collOpt = New Collection
For Each oCtl In Me.Controls
If TypeOf oCtl Is MSForms.OptionButton Then
Set formButton = New clsOpt
Set formButton.optButton = oCtl
collOpt.Add formButton
End If
Next oCtl
End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Flemming Dahl" wrote in message
...

Show/Hide dos not provide the flexiblity of how many controls the user
needs.
In this case i am not going to make alle those controls and show/hide
procedures..........

Lets stop it here. It seems that you can not provide any extra information
to solve my problem.

Thanks,
Flemming




  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Programmely written code don't work

Thanks Bob

This Class module I gotta try :)

Flemming


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
Userfrom code in written in Excel 2000 running in Excel 97 KimberlyC Excel Programming 1 February 11th 04 08:45 PM
Searching range for value (code written but needs 'tweaking'!) ian123[_26_] Excel Programming 8 December 23rd 03 05:19 PM
Code won't work? Joe 90 Excel Programming 3 October 2nd 03 04:26 AM
Why my code do not work : - ( keepitcool Excel Programming 5 September 5th 03 06:28 PM
Why my code do not work : - ( Tom Ogilvy Excel Programming 1 August 31st 03 04:53 PM


All times are GMT +1. The time now is 04:02 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"