您好我想将范围复制并粘贴到mainworkbook,但是,范围会粘贴在babyworkook8上。请帮忙
Option Explicit
Dim mainworkbook As Workbook
Dim babyworkbook8 As Workbook
Sub Copypaste()
Set babyworkbook8 = Workbooks.Open("\\C:\IT Charges\IT Charges August.xlsx")
babyworkbook8.Sheets("Sheet1").Range("D4:F27").Copy
Set mainworkbook = Workbooks.Open("\\C:\Users\ivan\Desktop\IT Charges\IT
Summary Charges.xlsm")
mainworkbook.Sheets("Sheet1").Range("R1").PasteSpecial
End Sub
答案 0 :(得分:0)
这有点长,但它清楚地定义了源和目标范围:
Sub CopyPaste()
Dim SourceBook As Workbook
Dim DestBook As Workbook
Dim SourceSheet As Worksheet
Dim DestSheet As Worksheet
Dim SourceRange As Range
Dim DestRange As Range
Set SourceBook = Workbooks.Open("\\C:\IT Charges\IT Charges August.xlsx")
Set DestBook = Workbooks.Open("\\C:\Users\ivan\Desktop\IT Charges\IT Summary Charges.xlsm")
Set SourceSheet = SourceBook.Sheets("Sheet1")
Set DestSheet = DestBook.Sheets("Sheet1")
Set SourceRange = SourceSheet.Range("D4:F27")
Set DestRange = DestSheet.Range("R1")
SourceRange.Copy DestRange
End Sub