VBA - 运行时错误“1004”

用户9773487

有点上下文,这是我第一次在 excel 中使用 VBA 进行编程,我正在尝试创建一个填写电子表格的表单。

我目前收到错误消息:“运行时错误‘1004’:对象‘_Global’的方法‘工作表’失败

我在网上搜索并尝试了各种解决方案,但我认为基本上归结为我缺乏理解。

Private Sub CommandButton1_Click()
'When pressing save, save values in spreedsheet locations
ActiveSheet.range("c8").Value = ContactName.Value
ActiveSheet.range("b19").Value = ModelNumber.Value
ActiveSheet.range("d19").Value = SerialNumber.Value
ActiveSheet.range("g19").Value = IncidentNumber.Value
ActiveSheet.range("j19").Value = Description.Value
ActiveSheet.range("c7").Value = PortLocation.Value

'save file
ActiveWorkbook.SaveAs Filename:= _
  "D:\Users\611281\Downloads\Zebra\EmailMeToZebra.xlsx", FileFormat:=xlOpenXMLWorkbook, ReadOnlyRecommended:=False, CreateBackup:=False

End 'after pressing save, close down sheet.

End Sub


Private Sub UserForm_Initialize()

Me.PortLocation.List = Worksheets("Data lookup_ports").range("e3:e200").Value

Dim MyTempWkBk As Workbook
Dim MyCurrentWin As Window

Set MyCurrentWin = ActiveWindow
Set MyTempWkBk = Workbooks.Open("D:\Users\611281\Downloads\Zebra\GUI.xlsm")
MyCurrentWin.Activate      'Allows only a VERY brief flash of the opened workbook
MyTempWkBk.Windows.Visible = False 'Only necessary if you also need to prevent
                                    'the user from manually accessing the opened
                                    'workbook before it is closed.

'Operate on the new workbook, which is not visible to the user, then close it...

End Sub

Private Sub UserForm_Terminate()
    End 'when pressing x, close down window, do not save.
End Sub

我收到代码错误:

Me.PortLocation.List = Worksheets("Data lookup_ports").range("e3:e200").Value

这只是我试图从电子表格范围填充 ListBox

亲爱的男孩

您是否尝试过命名工作簿?这是假设有错误的行指的是本工作簿中的单元格范围。此外,请务必检查您所指的工作表名称是否正确拼写(如果拼写正确,还要检查是否有滞后空格。)此外,工作表是否隐藏?如果是这样,这可能需要在调用工作表之前添加。

wb.sheets("Data lookup_ports").Visible = True  

同时可以尝试下面的编辑。

Private Sub UserForm_Initialize()

Dim MyTempWkBk As Workbook
Dim MyCurrentWin As Window
Dim WB as Workbook
   Set WB = ThisWorkBook
wb.sheets("Data lookup_ports").Visible = True 

Me.PortLocation.List = WB.Sheets("Data lookup_ports").Range("E3:E200").Value



Set MyCurrentWin = ActiveWindow
Set MyTempWkBk = Workbooks.Open("D:\Users\611281\Downloads\Zebra\GUI.xlsm")
MyCurrentWin.Activate   
MyTempWkBk.Windows.Visible = False 'Only necessary if you also need to prevent
                                'the user from manually accessing the opened
                                'workbook before it is closed.

'Operate on the new workbook, which is not visible to the user, then close it...

End Sub

Private Sub UserForm_Terminate()
    End 'when pressing x, close down window, do not save.
End Sub

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

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

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Excel VBA运行时错误1004

来自分类Dev

Excel VBA运行时错误1004

来自分类Dev

29738行后VBA运行时错误1004

来自分类Dev

使用vba搜索功能时运行时错误1004

来自分类Dev

Excel VBA Vlookup运行时错误1004

来自分类Dev

Excel VBA-运行时错误1004

来自分类Dev

Excel VBA查找函数获取运行时错误1004

来自分类Dev

VBA 运行时错误 1004:范围(“ ”)。公式

来自分类Dev

VBA错误:“运行时错误1004:应用程序定义或对象定义的错误”

来自分类Dev

运行时错误'1004':应用程序定义的错误或对象定义的错误VBA

来自分类Dev

范围的VBA运行时错误1004“应用程序定义的错误或对象定义的错误”

来自分类Dev

VBA - 运行此代码时出现运行时错误“1004”

来自分类Dev

VBA 运行时错误“1004”在一个完美运行的例程中

来自分类Dev

Excel VBA运行时错误1004“应用程序定义或对象定义的错误”

来自分类Dev

VBA Excel。运行时错误'1004'。应用程序定义或操作定义的错误

来自分类Dev

VBA运行时错误1004:应用程序定义或对象定义的错误

来自分类Dev

Excel VBA运行时错误1004“应用程序定义或对象定义的错误”

来自分类Dev

Excell VBA 运行时错误“1004”:应用程序定义或对象定义错误

来自分类Dev

VBA INDEX MATCH 运行时错误“1004”:应用程序定义或对象定义错误

来自分类Dev

在单元格中插入值或公式时,Excel VBA运行时错误1004

来自分类Dev

带有Count和Countif公式VBA的运行时错误1004

来自分类Dev

VBA运行时错误1004,提取范围的字段名称丢失或无效

来自分类Dev

为我的VBA复制和粘贴宏获取“运行时错误'1004'”

来自分类Dev

使用Excel VBA在工作簿中查找匹配项:运行时错误1004

来自分类Dev

VBA中具有索引和匹配的运行时错误1004

来自分类Dev

重命名ActiveSheet时Excel VBA运行时错误1004

来自分类Dev

VBA运行时错误1004的object_global范围失败

来自分类Dev

VBA运行时错误1004:对象“工作簿”的方法“ OpenText”失败

来自分类Dev

Excel VBA运行时错误1004 ActiveSheet.ListObject.Range.Autofilter

Related 相关文章

  1. 1

    Excel VBA运行时错误1004

  2. 2

    Excel VBA运行时错误1004

  3. 3

    29738行后VBA运行时错误1004

  4. 4

    使用vba搜索功能时运行时错误1004

  5. 5

    Excel VBA Vlookup运行时错误1004

  6. 6

    Excel VBA-运行时错误1004

  7. 7

    Excel VBA查找函数获取运行时错误1004

  8. 8

    VBA 运行时错误 1004:范围(“ ”)。公式

  9. 9

    VBA错误:“运行时错误1004:应用程序定义或对象定义的错误”

  10. 10

    运行时错误'1004':应用程序定义的错误或对象定义的错误VBA

  11. 11

    范围的VBA运行时错误1004“应用程序定义的错误或对象定义的错误”

  12. 12

    VBA - 运行此代码时出现运行时错误“1004”

  13. 13

    VBA 运行时错误“1004”在一个完美运行的例程中

  14. 14

    Excel VBA运行时错误1004“应用程序定义或对象定义的错误”

  15. 15

    VBA Excel。运行时错误'1004'。应用程序定义或操作定义的错误

  16. 16

    VBA运行时错误1004:应用程序定义或对象定义的错误

  17. 17

    Excel VBA运行时错误1004“应用程序定义或对象定义的错误”

  18. 18

    Excell VBA 运行时错误“1004”:应用程序定义或对象定义错误

  19. 19

    VBA INDEX MATCH 运行时错误“1004”:应用程序定义或对象定义错误

  20. 20

    在单元格中插入值或公式时,Excel VBA运行时错误1004

  21. 21

    带有Count和Countif公式VBA的运行时错误1004

  22. 22

    VBA运行时错误1004,提取范围的字段名称丢失或无效

  23. 23

    为我的VBA复制和粘贴宏获取“运行时错误'1004'”

  24. 24

    使用Excel VBA在工作簿中查找匹配项:运行时错误1004

  25. 25

    VBA中具有索引和匹配的运行时错误1004

  26. 26

    重命名ActiveSheet时Excel VBA运行时错误1004

  27. 27

    VBA运行时错误1004的object_global范围失败

  28. 28

    VBA运行时错误1004:对象“工作簿”的方法“ OpenText”失败

  29. 29

    Excel VBA运行时错误1004 ActiveSheet.ListObject.Range.Autofilter

热门标签

归档