VBA - 编译错误 - 未找到方法或数据成员
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27403461/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VBA - Compile Error - Method or Data member not Found
提问by Scott
I have been using this excel program for several months without issues. suddenly a couple days ago it started to throw this error. On sheet named "Input" I will double click a cell in column "A" which will create a drop down box that will fill with data from the "Data" sheet. I start typing and then I select the data to add to the cell. Now when I click the cell and get an error message "Compile Error - Method or data member not found". Here is my block of code and the error is showing near the bottom highlighting "Me.TempCombo.Activate".
我一直在使用这个 excel 程序几个月没有问题。突然几天前它开始抛出这个错误。在名为“输入”的工作表上,我将双击“A”列中的一个单元格,这将创建一个下拉框,其中将填充“数据”工作表中的数据。我开始输入,然后选择要添加到单元格的数据。现在,当我单击单元格并收到错误消息“编译错误 - 未找到方法或数据成员”时。这是我的代码块,错误显示在突出显示“Me.TempCombo.Activate”的底部附近。
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim str As String
Dim cboTemp As OLEObject
Dim ws As Worksheet
Set ws = ActiveSheet
If Target.Column = 1 And Target.Row > 12 And Target.Row <> HRRow And Target.Row <> HRRow - 1 Then
lRow = Sheets("Data").Range("A65536").End(xlUp).Row
Set cboTemp = ws.OLEObjects("TempCombo")
On Error Resume Next
With cboTemp
'clear and hide the combo box
.ListFillRange = ""
.LinkedCell = ""
.Visible = False
End With
On Error GoTo errHandler
'If Target.Validation.Type = 3 Then
'if the cell contains a data validation list
Cancel = True
Application.EnableEvents = False
'get the data validation formula
'str = Target.Validation.Formula1
'str = Right(str, Len(str) - 1)
str = "=Data!A2:A" & lRow
With cboTemp
'show the combobox with the list
.Visible = True
.Left = Target.Left
.Top = Target.Top
.Width = Target.Width + 5
.Height = Target.Height + 5
.ListFillRange = str
.LinkedCell = Target.Address
End With
'cboTemp.Activate
Me.TempCombo.Activate
'open the drop down list automatically
Me.TempCombo.DropDown
End If
errHandler:
Application.EnableEvents = True
Exit Sub
End Sub
I tried several things and for the life of me I cannot figure out what changed. Any help will be appreciated. Thank you.
我尝试了几件事,对于我的生活,我无法弄清楚发生了什么变化。任何帮助将不胜感激。谢谢你。
回答by Tom
I ran into the same error and was able to solve it as Rory suggested. I searched my machine for *.exd files and found a few. The issue was solved for me after removing C:\Users\<username>\AppData\Local\Temp\Excel8.0\MSForms.exd...the others seemed to be unrelated to the ActiveX controls in Excel.
我遇到了同样的错误,并且能够按照 Rory 的建议解决它。我在我的机器上搜索了 *.exd 文件并找到了一些。删除后问题为我解决了C:\Users\<username>\AppData\Local\Temp\Excel8.0\MSForms.exd......其他似乎与Excel中的ActiveX控件无关。
回答by Lefty
Looks like the code came from an example like this: http://www.contextures.com/xlDataVal10.html
看起来代码来自这样的例子:http: //www.contextures.com/xlDataVal10.html
except your code has commented out the line which activates the cboTemp combobox. Your code is attempting to access the TempCombo attribute of the worksheet (which I don't think exists). Uncomment 'cboTemp.Activateon the line above the highlighted error line.
除了您的代码已注释掉激活 cboTemp 组合框的行。您的代码试图访问工作表的 TempCombo 属性(我认为不存在)。取消注释'cboTemp.Activate突出显示的错误行上方的行。
回答by Fossie
I had the same problem, my code broke this morning. Fortunately, I recalled that I ran Windows Update this weekend. I performend a system restore (earliest available restore point was 8th of december), and now the problem is gone.
我有同样的问题,今天早上我的代码坏了。幸运的是,我记得我这个周末运行了 Windows Update。我执行了系统还原(最早可用的还原点是 12 月 8 日),现在问题消失了。
I never did understand the panicy server guys who were always making backups and spending a whole lot of time testing before/after system updates, in all my years I never experienced any problems. Now I sure figured out what they were talking about. Lesson learnt. I'll try running win update again in a few months, hopefully MS has solved the problem by then.
我从来没有理解那些总是在系统更新之前/之后进行备份并花费大量时间进行测试的恐慌服务器人员,这些年来我从未遇到过任何问题。现在我肯定知道他们在说什么了。学习到教训了。我会在几个月后再次尝试运行 win update,希望到那时 MS 已经解决了这个问题。
Best of luck
祝你好运

