form will not show when VBE is modified

bigt95nt

New Member
Joined
Apr 11, 2011
Messages
26
When the following code is executed, the form that the controls (CheckBoxes 1 to n) are created on fails to "Show" on the sheet. However the form appears in the project window with the correct number CheckBox Controls and if "RUN FORM" is selected the form apears on the sheet and each control works properly when each CheckBox is selected.

If on the other hand, if the code is commented out, the form displays on the sheet with the correct number of CheckBox controls, but no functionality
NOTE: the code shown is in a FOR NEXT loop and is not shown in its entirity.

Any comment would be greatly appreciated!

With TempForm.CodeModule
Line = .CountOfLines
.InsertLines Line + 1, "Sub Checkbox" & i & "_Change()"
.InsertLines Line + 2, " if ActiveChart.SeriesCollection(" & i & ").Format.Line.visible = True then"
.InsertLines Line + 3, ""
.InsertLines Line + 4, "ActiveChart.SeriesCollection(" & i & ").Format.Line.visible= False"
.InsertLines Line + 5, "exit sub"
.InsertLines Line + 6, "else ActiveChart.SeriesCollection(" & i & ").Format.Line.visible= True"
.InsertLines Line + 7, ""
.InsertLines Line + 8, "exit sub"
.InsertLines Line + 9, "end if"
.InsertLines Line + 10, "End Sub"
End With
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
I'm out of ideas. Sorry.

As a test. Try this...

Code:
With TempForm.CodeModule
Line = .CountOfLines
.InsertLines Line + 1, ""
.InsertLines Line + 2, "Sub Checkbox" & i & "_Change()"
.InsertLines Line + 3, "    MsgBox " & i
.InsertLines Line + 4, "End Sub"
End With
Next i
 
Last edited:
Upvote 0
No Same as before. Does not appear on the Sheet, but works fine if run by using "run form"

tHANK YOU FOR YOUR TIME
 
Upvote 0
Update:
Playing with code hopeing to find a solution I changed the folowlling:

.Properties("ShowModal") = False' to

.Properties("ShowModal") = True

this caused the form to display correctly on the user sheet, and each CheckBox Functioned correctly; however, this is no good because I must be able to select elements on the sheet so the property must be set to "false"

Any sugestions?

Please comment

Ton
 
Upvote 0
Where in the code are you setting .Properties("ShowModal") = False ?
I thought you had posted the entire code?
 
Upvote 0
Below is the entire code:

Sub LegendControl(oChart As ChartStruct)
Dim iCount As Integer, i As Integer
'Dim NewCheckBox As Object
Dim dTop As Double, dLeft As Double, dheight As Double, dWidth As Double, WidthIndex As Double
Dim TempForm As Object 'VBComponent
Dim NewCheckBox As MSForms.CheckBox
Dim Line As Integer
Dim TheForm As New DataScape
Call DeleteUserForms
Set TempForm = ThisWorkbook.VBProject. _
VBComponents.Add(3) 'vbext_ct_MSForm
With oChart.TrendLegend
dTop = .dGetLegendTop
dLeft = .dGetLegendLeft
dWidth = .dGetLegendWidth
dheight = .dGetLegendHeight
End With

Application.VBE.MainWindow.Visible = False
With TempForm
.Properties("Caption") = TempForm.Name
.Properties("Width") = dWidth
.Properties("Height") = dheight
.Properties("Top") = dTop
.Properties("left") = dLeft
.Properties("ShowModal") = False
End With

iCount = oChart.TrendLegend.GetCount
WidthIndex = 1
'ThisWorkbook.VBProject.VBComponents.Add (3)
For i = iCount To 1 Step -1
Set NewCheckBox = TempForm.Designer.Controls _
.Add("forms.CheckBox.1")

With oChart.TrendLegend

NewCheckBox.Caption = i & " " & .GetText(i)
NewCheckBox.Left = 1
NewCheckBox.Top = WidthIndex
NewCheckBox.Width = .GetWidth(i)
NewCheckBox.Height = .GetLength(i) + 5
WidthIndex = WidthIndex + .GetLength(i)
NewCheckBox.Font = .GetFont(i)
NewCheckBox.ForeColor = .GetColor(i)
NewCheckBox.Value = True
NewCheckBox.Name = "CheckBox" & i
End With

With TempForm.CodeModule
Line = .CountOfLines
.InsertLines Line + 1, "Sub Checkbox" & i & "_Change()"
.InsertLines Line + 2, " if ActiveChart.SeriesCollection(" & i & ").Format.Line.visible = True then"
.InsertLines Line + 3, ""
.InsertLines Line + 4, "ActiveChart.SeriesCollection(" & i & ").Format.Line.visible= False"
.InsertLines Line + 5, "exit sub"
.InsertLines Line + 6, "else ActiveChart.SeriesCollection(" & i & ").Format.Line.visible= True"
.InsertLines Line + 7, "" .InsertLines Line + 8, "exit sub"
.InsertLines Line + 9, "end if"
.InsertLines Line + 10, "End Sub"
End With
Next i
VBA.UserForms.Add(TempForm.Name).Show

End Sub
 
Upvote 0
Why are you using code to create the whole userform and add code for the controls?

Why not create a class module to handle the checkboxes?

You could still add the checkboxes dynamically at runtime.
 
Upvote 0
Im am going to eventualy roll this routine into a class, but trying to get this bit of code up and running before adding an other layer of complexity from a class
 
Upvote 0

Forum statistics

Threads
1,224,612
Messages
6,179,890
Members
452,948
Latest member
Dupuhini

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top