我正在尝试从文件夹中打开工作簿FName
并从中复制一个范围并粘贴到新工作簿WBNew
中,但我一直收到错误
下标超出范围或1004 - 应用程序定义
错误。
知道为什么吗?
Sub NewNumbers()
Dim FName As Workbook, WBNew As Workbook
Set FName = Workbooks.Open(Range("C3") & "\" & Range("C2"))
Set WBNew = Workbooks.Add
FName.Worksheets("Numbers").Range("U2", Range("U2").End(xlToRight)).Copy
WBNew.Sheets("Sheet1").Paste
End Sub
答案 0 :(得分:0)
复制>>粘贴是一个单行命令,还在Range
中定义"Sheet1"
以粘贴。
Dim NumbersSht As Worksheet
' set the copied sheet object
Set NumbersSht = FName.Worksheets("Numbers")
With NumbersSht
.Range("U2", .Range("U2").End(xlToRight)).Copy Destination:=WBNew.Sheets("Sheet1").Range("A1") '<--- Modify "A1" to your desired range
End With