Database “粘贴”给出;“所需对象”;错误
我得到这个错误: 错误424:需要对象 在这一行:Database “粘贴”给出;“所需对象”;错误,database,vba,Database,Vba,我得到这个错误: 错误424:需要对象 在这一行: ActiveSheet.Paste Destination:=Worksheets("Sheet1").Range(Cells(erow, 1), Cells(erow, 1)) 在下面的代码中。为什么? Sub LoopThroughDirectory() Dim MyFile As String Dim erow Dim Filepath As String Filepath = "C:\User
ActiveSheet.Paste Destination:=Worksheets("Sheet1").Range(Cells(erow, 1), Cells(erow, 1))
在下面的代码中。为什么?
Sub LoopThroughDirectory()
Dim MyFile As String
Dim erow
Dim Filepath As String
Filepath = "C:\Users\Julio Jesus Sanchez\Desktop\MRSK TXT\"
MyFile = Dir("C:\Users\Julio Jesus Sanchez\Desktop\MRSK TXT\")
Do While Len(MyFile) > 0
If MyFile = "MRSK DATABASE.xlsm" Then
Exit Sub
End If
Workbooks.Open (Filepath & MyFile)
Range("A1:K1").Copy
ActiveWorkbook.Close
erow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
ActiveSheet.Paste Destination:=Worksheets("Sheet1").Range(Cells(erow, 1), Cells(erow, 1))
MyFile = Dir
Loop
End Sub
关闭
ActiveWorkbook
,然后参考ActiveSheet
,这是什么意思?如果您参考的是母版手册,那么您应该明确地告诉它,通过将其设置为对象,您的VBA是否也在MS Access模块或Excel中?您刚刚将其标记为数据库
和VBA
,我猜是Excel,因为您没有任何对Excel对象的引用
Dim sh as Worksheet
Set sh = Workbooks("NameOfWorkBook.xlsx").WorkSheets("WorksheetName")
然后,每当您参考工作表时:
sh.Paste Destination:=sh.Range(Cells(erow, 1), Cells(erow, 1))
你为什么认为这是个错误?您是否收到错误?是的,它表示这是一个“424”错误,并且需要一个对象。哪一行引发了错误?请帮助我们帮助您。我们怎么可能用这么少的信息来回答这个问题呢?我们在这里帮助(希望如此),而不是解决难题。ActiveSheet.Paste目标:=工作表(“Sheet1”)。范围(单元格(erow,1),单元格(erow,1))