需要解决:“抱歉,发生错误的对象不支持此属性或方法”

来了

我的代码使用来自用户窗体中一组文本框的信息来查找和编辑两个工作簿中的值。我用来编辑第二个工作簿中的值的代码给了我以下错误,“很抱歉,发生的错误对象不支持此属性或方法”。谁能帮我这个?除了导致错误的原因之外,我认为我的代码是正确的,但如果有人发现我的代码中有任何错误,请随时纠正我或提供建议。提前致谢!

Private Sub Submit_Click()
Dim WS As Worksheet
Dim lastrow As Long
Dim r As Long
Dim password As String

Application.ScreenUpdating = False
If Not IsNumeric(TextBox1.Text) Then
On Error GoTo ErrorHandler
password = TextBox1.Text
Set WS = ActiveWorkbook.Worksheets("Accounts")
lastrow = WS.Cells(Rows.Count, "A").End(xlUp).Row
For r = 2 To lastrow
If WS.Cells(r, 2) = Label5.Caption Then
WS.Cells(r, 2).Value = TextBox1.Text
WS.Cells(r, 3).Value = TextBox2.Text
WS.Cells(r, 4).Value = TextBox3.Text
MsgBox "Update Successful", vbInformation
TextBox1.Text = ""
Call Edit_Login
Application.ScreenUpdating = True
Exit Sub
End If
Next
MsgBox "Data not Found!!", vbCritical
TextBox1.Text = ""
Unload Me
Application.ScreenUpdating = True
Exit Sub
ErrorHandler: MsgBox "Sorry an Error occured. " & vbCrLf & Err.Description
Exit Sub
End If
MsgBox "Please Enter Correct Information", vbCritical
Application.ScreenUpdating = True
End Sub

Private Sub Edit_Login()
Dim Wkbk As Workbook
Dim txt As String
Dim txt2 As String
Dim txt3 As String
Dim lastrow As Long
Dim r As Long
Dim Account As String

Application.ScreenUpdating = False
Application.EnableEvents = False
Application.DisplayAlerts = False
If Not IsNumeric(TextBox1.Text) Then
On Error GoTo ErrorHandler
Account = TextBox1.Text
Set Wkbk = Workbooks.Open("C:\Users\kameron\Desktop\Quality Improvement 
Software\Log In.xlsm")
lastrow = Wkbk.Cells(Rows.Count, "A").End(xlUp).Row
For r = 2 To lastrow
If Wkbk.Sheets("Tables").Cells(r, 1) = Label5.Caption Then
Wkbk.Sheets("Tables").Cells(r, 1).Value = TextBox1.Text
Wkbk.Sheets("Tables").Cells(r, 2).Value = TextBox2.Text
Wkbk.Sheets("Tables").Cells(r, 3).Value = TextBox3.Text
MsgBox "Update Successful", vbInformation
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
Unload EditAccount
Application.ScreenUpdating = True
Exit Sub
End If
Next
MsgBox "Data not Found!!", vbCritical
TextBox1.Text = ""
Unload Me
Application.ScreenUpdating = True
Exit Sub
ErrorHandler: MsgBox "Sorry an Error occured. " & vbCrLf & Err.Description
Exit Sub
End If
MsgBox "Please Enter Correct Information", vbCritical
Application.ScreenUpdating = True
Application.EnableEvents = True
Application.DisplayAlerts = True
End Sub
约翰科尔曼

问题是线路

lastrow = Wkbk.Cells(Rows.Count, "A").End(xlUp).Row

工作簿对象没有Cells属性。

在上下文中,您似乎想要

lastrow = Wkbk.Sheets("Tables").Cells(Rows.Count, "A").End(xlUp).Row

为了追踪此错误,您可以执行以下两项操作之一:

1) 使用 F8 单步执行代码并查看它在哪一行失败。

2)暂时注释掉该行On Error GoTo ErrorHandler并运行代码。

任何一种方法都会很快导致那条线。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Rails:类型错误:对象不支持此属性或方法

来自分类Dev

对象不支持此属性或方法

来自分类Dev

对象不支持此属性或方法

来自分类Dev

对象不支持此属性或方法

来自分类Dev

对象不支持此属性或方法

来自分类Dev

对象不支持此属性或方法ActiveWorkbook对象VBA

来自分类Dev

错误438对象不支持此属性或方法-带字典的类对象

来自分类Dev

Internet Explorer 中的 jQuery 错误 - 发生对象不支持属性或方法“addEventListener”

来自分类Dev

VBA对象不支持此属性或方法

来自分类Dev

调试-IE对象不支持此属性或方法

来自分类Dev

对象不支持此属性或方法:oFldr.GetFolder

来自分类Dev

对象不支持此属性或方法Chartspace

来自分类Dev

对象在VBA中不支持此属性或方法

来自分类Dev

用户定义类 - 对象不支持此属性或方法

来自分类Dev

Excel VBA错误438:对象不支持此属性或方法

来自分类Dev

Javascript错误:对象在IE浏览器中不支持此属性或方法

来自分类Dev

为什么出现此错误:对象不支持Internet Explorer的属性或方法“ forEach”?

来自分类Dev

遇到运行时错误'438'对象在Excel宏中不支持此属性或方法

来自分类Dev

IE为什么会出现此错误:对象不支持属性或方法isNaN

来自分类Dev

IE8 JS错误:对象不支持此属性或方法

来自分类Dev

“运行时错误'438':对象不支持此属性或方法。” 范围值=范围值

来自分类Dev

仅在IE8中的jQuery错误“对象不支持此属性或方法”

来自分类Dev

为什么出现此错误:对象不支持Internet Explorer的属性或方法“ forEach”?

来自分类Dev

IE8 Javascript错误:对象不支持此属性或方法

来自分类Dev

Excel VBA,错误“ 438”“对象不支持此属性或方法”

来自分类Dev

IE为什么会出现此错误:对象不支持属性或方法isNaN

来自分类Dev

IE8 JavaScript错误-对象不支持此属性或方法

来自分类Dev

IE8 JS错误:对象不支持此属性或方法

来自分类Dev

Excel VBA错误438:对象不支持此属性或方法

Related 相关文章

  1. 1

    Rails:类型错误:对象不支持此属性或方法

  2. 2

    对象不支持此属性或方法

  3. 3

    对象不支持此属性或方法

  4. 4

    对象不支持此属性或方法

  5. 5

    对象不支持此属性或方法

  6. 6

    对象不支持此属性或方法ActiveWorkbook对象VBA

  7. 7

    错误438对象不支持此属性或方法-带字典的类对象

  8. 8

    Internet Explorer 中的 jQuery 错误 - 发生对象不支持属性或方法“addEventListener”

  9. 9

    VBA对象不支持此属性或方法

  10. 10

    调试-IE对象不支持此属性或方法

  11. 11

    对象不支持此属性或方法:oFldr.GetFolder

  12. 12

    对象不支持此属性或方法Chartspace

  13. 13

    对象在VBA中不支持此属性或方法

  14. 14

    用户定义类 - 对象不支持此属性或方法

  15. 15

    Excel VBA错误438:对象不支持此属性或方法

  16. 16

    Javascript错误:对象在IE浏览器中不支持此属性或方法

  17. 17

    为什么出现此错误:对象不支持Internet Explorer的属性或方法“ forEach”?

  18. 18

    遇到运行时错误'438'对象在Excel宏中不支持此属性或方法

  19. 19

    IE为什么会出现此错误:对象不支持属性或方法isNaN

  20. 20

    IE8 JS错误:对象不支持此属性或方法

  21. 21

    “运行时错误'438':对象不支持此属性或方法。” 范围值=范围值

  22. 22

    仅在IE8中的jQuery错误“对象不支持此属性或方法”

  23. 23

    为什么出现此错误:对象不支持Internet Explorer的属性或方法“ forEach”?

  24. 24

    IE8 Javascript错误:对象不支持此属性或方法

  25. 25

    Excel VBA,错误“ 438”“对象不支持此属性或方法”

  26. 26

    IE为什么会出现此错误:对象不支持属性或方法isNaN

  27. 27

    IE8 JavaScript错误-对象不支持此属性或方法

  28. 28

    IE8 JS错误:对象不支持此属性或方法

  29. 29

    Excel VBA错误438:对象不支持此属性或方法

热门标签

归档