我正在尝试从文件夹中打开工作簿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
复制>>粘贴是一个 1 行命令,还要定义一个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