Run-time Error 424 Object Required UserForm doesnt exist

匿名 (未验证) 提交于 2019-12-03 01:00:01

问题:

I'm attempting to do the things written on this site www.excel-easy.com but when I click the commandbutton (from ActiveX controls) in the worksheet just like what the website instructed, nothing happens. I tried to use a button from form controls, but it says that the error is in this ---> DinnerPlannerUserForm.Show

My Code:

Sub Button2_Click()     DinnerPlannerUserForm.Show End Sub

When I used F8, it said the error is here --> Private Sub UserForm_Initialize()

Private Sub UserForm_Initialize()      'Empty NameTextBox     NameTextBox.Value = ""      'Empty PhoneTextBox     PhoneTextBox.Value = ""      'Empty CityListBox     CityListBox.Clear      'Fill CityListBox     With CityListBox         .AddItem "San Francisco"         .AddItem "Oakland"         .AddItem "Richmond"     End With      'Empty DinnerComboBox     DinnerComboBox.Clear      'Fill DinnerComboBox     With DinnerComboBox         .AddItem "Italian"         .AddItem "Chinese"         .AddItem "Frites and Meat"     End With      'Uncheck DataCheckBoxes     DateCheckBox1.Value = False     DateCheckBox2.Value = False     DateCheckBox3.Value = False      'Set no car as default     CarOptionButton2.Value = True      'Empty MoneyTextBox     MoneyTextBox.Value = ""      'Set Focus on NameTextBox     NameTextBox.SetFocus  End Sub

回答1:

This error can also occur when you remove or delete a textbox from your form, but forget to remove it from a line in initialization for eg:

Private Sub UserForm_Initialize()     CommandButton2.Enabled = False     TextBox4.Enabled = False    'textbox deleted from form End sub


回答2:

I was able to solve these by changing

Private Sub UserForm_Initialize()

to

Private Sub DinnerPlannerUserForm_Initialize()

See if it works



回答3:

Hard to tell based on what you have said. But -- the fact that you said using F8 indicated that the error is in Private Sub UserForm_Initialize() suggests that the userform exists and VBA knows how to find it (otherwise its initialize event wouldn't be firing when you click the form button). Hence -- it is one of the lines in the initialize sub which is the culprit. Which line specifically is flagged? I'm guessing that a simple typo in the name of one of the controls (e.g. DinnerComboBox) is the problem.



回答4:

I'm assuming this issue has been resolved, but for anyone just now looking at it. I had this issue and it turned out to be that I had removed a ComboBox from my form, but it was still referenced in the code. Once I removed that section of the code, it worked beautifully.



回答5:

I was using the same tutorial and solved the problem by changing the Initialize command:

It is given as

Private Sub UserForm_Initialize()

I named my user form (for my own purposes)

StdTimeCalculatorForm

and changing the code to

Private Sub StdTimeCalculatorForm_Initialize()

solved the problem. Hope this helps.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!