gpt4 book ai didi

excel - 将工作簿的内容复制到另一个工作簿

转载 作者:行者123 更新时间:2023-12-04 21:52:01 26 4
gpt4 key购买 nike

我想将工作簿的工作表的内容复制到另一个工作簿。

此代码仅打开两个工作簿,而不是复制和粘贴值。

Sub btnClickMev2()
Dim x As Workbook
Dim y As Workbook

'Open Workbooks
Set x = Workbooks.Open("H:\Desktop\test.xls")
Set y = Workbooks.Open("H:\Desktop\Book1v3.xlsm")

'Copy from x Workbook
x.Sheets("Query2").Range("A1:T1036").Copy
'Paste to Y Workbook
y.Sheets("Sheet2").Range("A1:T1036").PasteSpecial
'Close x:
x.Close
End Sub

最佳答案

希望这会有所帮助,在此 Thread 上找到并为您的代码重写:

Sub foo3()
Dim x As Workbook
Dim y As Workbook
Dim vals as Variant

'## Open both workbooks first:
Set x = Workbooks.Open("H:\Desktop\test.xls")
Set y = Workbooks.Open("H:\Desktop\Book1v3.xlsm")

'Store the value in a variable:
vals = x.Sheets("Query2").Range("A1:T1036").Value

'Use the variable to assign a value to the other file/sheet:
y.Sheets("Sheet2").Range("A1:T1036").Value = vals

'Close x:
x.Close

End Sub

关于excel - 将工作簿的内容复制到另一个工作簿,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52259291/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com