EXCEL VBA 运行时错误1004 应用程序定义或对象定义错误
我想把几张表复制粘贴到一张表里,然后试了几种方法,包括注释里的,都是1004,求帮助Subadd()Dima!,b!,c!,i!,j!DimwbAsWorkbookDim...
我想把几张表复制粘贴到一张表里,然后试了几种方法,包括注释里的,都是1004,求帮助
Sub add()
Dim a!, b!, c!, i!, j!
Dim wb As Workbook
Dim rng As Range
Dim mypath As String
Dim myname As String
mypath = ThisWorkbook.Path & "\"
myname = Dir(mypath, vbDirectory)
Do While myname <> ""
If InStr(myname, "_表格") <> 0 Then
Set wb = Application.Workbooks.Open(mypath & myname)
a = Sheets(1).Range("A100").End(xlUp).Row
b = Sheets(1).Range("IV1").End(xlToLeft).Column
'MsgBox (a)
'MsgBox (b)
'ThisWorkbook.Sheets(1).Range(Cells(a, b)).CurrentRegion.Copy wb.Sheets(1).Range("Cells(i, b)")
'Set rng = wb.Sheets(1).Range(Cells(1, 1), Cells(a, b))
'rng.Copy
'rng.Clear
'Set rng = ThisWorkbook.Sheets(1).Range(Cells(c + 1, 1))
'rng.PasteSpecial Paste:=xlPasteValues
'wb.Sheets(1).Range(Cells(1, 1), Cells(a, b)).Copy
'ThisWorkbook.Sheets(1).Range(Cells(c + 1, 1)).PasteSpecial Paste:=xlPasteValues
For i = 1 To a
For j = 1 To b
If j > b Then
GoTo NI4
End If
wb.Sheets(1).Range(Cells(i, j)).Copy
ThisWorkbook.Sheets(1).Range(Cells(c + 1, j)).PasteSpecial Paste:=xlPasteValues
Next j
NI4:
Next
wb.Close
c = c + 2
MsgBox (c)
End If
myname = Dir
Loop
End Sub
我已经找到答案了。VBA还是不熟啊。
ThisWorkbook.Sheets(1).Cells(c + i, j).Value = wb.Sheets(1).Cells(i, j).Value 展开
Sub add()
Dim a!, b!, c!, i!, j!
Dim wb As Workbook
Dim rng As Range
Dim mypath As String
Dim myname As String
mypath = ThisWorkbook.Path & "\"
myname = Dir(mypath, vbDirectory)
Do While myname <> ""
If InStr(myname, "_表格") <> 0 Then
Set wb = Application.Workbooks.Open(mypath & myname)
a = Sheets(1).Range("A100").End(xlUp).Row
b = Sheets(1).Range("IV1").End(xlToLeft).Column
'MsgBox (a)
'MsgBox (b)
'ThisWorkbook.Sheets(1).Range(Cells(a, b)).CurrentRegion.Copy wb.Sheets(1).Range("Cells(i, b)")
'Set rng = wb.Sheets(1).Range(Cells(1, 1), Cells(a, b))
'rng.Copy
'rng.Clear
'Set rng = ThisWorkbook.Sheets(1).Range(Cells(c + 1, 1))
'rng.PasteSpecial Paste:=xlPasteValues
'wb.Sheets(1).Range(Cells(1, 1), Cells(a, b)).Copy
'ThisWorkbook.Sheets(1).Range(Cells(c + 1, 1)).PasteSpecial Paste:=xlPasteValues
For i = 1 To a
For j = 1 To b
If j > b Then
GoTo NI4
End If
wb.Sheets(1).Range(Cells(i, j)).Copy
ThisWorkbook.Sheets(1).Range(Cells(c + 1, j)).PasteSpecial Paste:=xlPasteValues
Next j
NI4:
Next
wb.Close
c = c + 2
MsgBox (c)
End If
myname = Dir
Loop
End Sub
我已经找到答案了。VBA还是不熟啊。
ThisWorkbook.Sheets(1).Cells(c + i, j).Value = wb.Sheets(1).Cells(i, j).Value 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询