朋友发给我一个他们下载并且已经使用了一段时间的电子表格,现在他们点击他们获得的单元格时随时都可以:
Run-time error '1004': Method 'OLEObjects' of object'_Worksheet' failed.
我收到同样的错误。我对visual basic完全没有了解,所以当我尝试找出代码中发生了什么时,我想在这里发布我的错误。任何帮助表示赞赏。三江源。
错误调试程序突出显示
行Set cboTemp = ws.OLEObjects("TempCombo")
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim str As String
Dim cboTemp As OLEObject
Dim ws As Worksheet
Set ws = ActiveSheet
Set cboTemp = ws.OLEObjects("TempCombo")
On Error GoTo errHandler
If Target.Column <> 3 Then
If cboTemp.Visible = True Then
With cboTemp
.Visible = False
.Top = 10
.Left = 10
'.ListFillRange = ""
.LinkedCell = ""
TempCombo.Value = ""
TempCombo.Clear
End With
End If
End If
On Error GoTo errHandler
If Target.Column = 3 Then
With cboTemp
'show the combobox with the list
.Left = Target.Left
.Top = Target.Top
.Width = Target.Width
.Height = Target.Height + 5
'.ListFillRange = ws.Range("pickdata").Address
'ws.Range("AB2", ws.Range("AB2").End(xlDown).Address).Address
' ws.Range("AB2").End(xlDown).Address
' ws.Range("AB2", "ab300").Address
' ws.Range(str).Address
.LinkedCell = Target.Address
.Visible = True
End With
cboTemp.Activate
TempCombo_Change 'force the combobox to fill
End If
exitHandler:
Application.ScreenUpdating = True
Application.EnableEvents = True
Exit Sub
errHandler:
MsgBox Err.Number & Err.Description
GoTo exitHandler ' Application.EnableEvents = True
Exit Sub
End Sub
Private Sub TempCombo_Change()
Dim cboTemp As OLEObject
Dim s As String, i As Long
Dim rng As Range, cell As Range, j As Long, fullmatch As Boolean
Dim ar() As String
If TempCombo.ListIndex >= 0 Then 'we have a selection
Else
'TempCombo.DropDown
If pickdata Is Nothing Then
SetPickData
Else
If LCase(Left(ActiveCell.Offset(0, 1).Value, 9)) = "cleanable" And activedbclean = False Then
SetPickData
Else
If LCase(Left(ActiveCell.Offset(0, 1).Value, 9)) <> "cleanable" And activedbclean = True Then
SetPickData
End If
End If
End If
Set rng = pickdata
'Set cboTemp = ActiveSheet.OLEObjects("TempCombo")
s = TempCombo.Value
TempCombo.Clear
i = 0
For Each cell In rng
ar = Split(s, " ", -1, vbBinaryCompare)
j = 0
fullmatch = True
Do While j <= UBound(ar) And fullmatch = True
If InStr(1, LCase(cell.Value), LCase(ar(j)), vbTextCompare) <= 0 Then
fullmatch = False
End If
j = j + 1
Loop
If fullmatch = True Then 'InStr(1, LCase(cell.Value), LCase(s), vbTextCompare) > 0 Then
'If InStr(1, LCase(cell.Value), LCase(s), vbTextCompare) > 0 Then
TempCombo.AddItem cell.Value
'If s = "" Then
i = i + 1
'End If
End If
If i > 50 Then
Exit For
End If
Next cell
TempCombo.Enabled = False
TempCombo.Enabled = True
TempCombo.DropDown
End If
End Sub
答案 0 :(得分:0)
我把它全部放在一张新的Excel表格中。这个人想要的是什么谢谢大家的帮助。