Pookiemeister
Well-known Member
- Joined
- Jan 6, 2012
- Messages
- 626
- Office Version
- 365
- 2010
- Platform
- Windows
I'm getting the following error. When I click Ok, the next message box that appears states "Out of Memory". I tried closing all the open apps. Eliminated any unused public variables. What else should I do? This all started when I created this sub routine. I' not sure if this has anything to do with this error.
VBA Code:
Sub CreateUserForm()
Dim myForm As Object
Dim NewFrame As MSForms.Frame
Dim NewButton As MSForms.CommandButton
Dim NewComboBox As MSForms.ComboBox
Dim NewListBox As MSForms.ListBox
Dim NewTextBox As MSForms.TextBox
Dim NewLabel As MSForms.Label
Dim NewOptionButton As MSForms.OptionButton
Dim NewCheckBox As MSForms.CheckBox
Dim X As Integer
Dim Line As Integer
'This is to stop screen flashing while creating form
Application.VBE.MainWindow.Visible = False
Set myForm = ThisWorkbook.VBProject.VBComponents.Add(3)
'Create the User Form
With myForm
.Properties("Caption") = "Edit Email Addresses"
.Properties("Width") = 300
.Properties("Height") = 20
End With
'Create TextBox
Set NewTextBox = myForm.designer.Controls.Add("Forms.textbox.1")
With NewTextBox
.Name = "txtbx_1"
.Top = 10
.Left = 10
.Width = 150
.Enabled = False
.Font.Size = 8
.Font.Name = "Tahoma"
.BorderStyle = fmBorderStyleSingle
.SpecialEffect = fmSpecialEffectSunken
End With
'Create CheckBox
Set NewCheckBox = myForm.designer.Controls.Add("Forms.checkbox.1")
With NewCheckBox
.Name = "chkbx_1"
.Top = 10
.Left = 160
.Caption = ""
.Width = 10
End With
'Create CommandButton Create
Set NewButton = myForm.designer.Controls.Add("Forms.commandbutton.1")
With NewButton
.Name = "cmd_1"
.Caption = "clickMe"
.Accelerator = "M"
.Top = 10
.Left = 200
.Width = 66
.Height = 20
.Font.Size = 8
.Font.Name = "Tahoma"
.BackStyle = fmBackStyleOpaque
End With
'add code for textBox
myForm.codemodule.insertlines 1, "Private Sub UserForm_Initialize()"
myForm.codemodule.insertlines 2, " If Me.chkbx_1.value = True Then "
myForm.codemodule.insertlines 3, " Me.txtbx_1.Enabled = True "
myForm.codemodule.insertlines 4, " End If "
myForm.codemodule.insertlines 5, "End Sub"
'Show the form
VBA.UserForms.Add(myForm.Name).Show
End Sub