![](/img/trans.png)
[英]How to copy then paste formulas from one workbook to another with VBA
[英]VBA to copy from one workbook and paste to another
工作:將RANGE從一個WORKBOOK復制到另一個(另一個工作簿存在且需要打開)
復制范圍:
`Worksheets("paste").Range("A2:BD500").SpecialCells(xlCellTypeVisible).Copy`
打開新文件:
Workbooks.Open Filename:="C:\\Test\\test.xlsx", WriteResPassword:="WriteFile"
激活工作表並粘貼@RANGE A6
Windows("test.xlsx").Activate Selection.Range("A6").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False
問題:它不會粘貼在A6 !!!! 它進入任何細胞!!!!
如果test.xlsx工作簿中的當前選擇打開到D5,則使用Selection.Range("A6")
引用D10,而不是A6。
Dim wb As Workbook
Set wb = Workbooks.Open(Filename:="C:\Test\test.xlsx", WriteResPassword:="WriteFile")
With Worksheets("paste")
.Range("A2:BD500").SpecialCells(xlCellTypeVisible).Copy
wb.Worksheets(1).Cells(6, "A").PasteSpecial xlPasteValues
End With
請參見如何避免在Excel VBA宏中使用“選擇” 。 打開工作簿時,不應該依賴靜態單元格或單元格作為當前選擇。
在工作簿之間復制特定范圍的簡單方法:
Workbooks(source).Worksheets("Sheet1").Range("A2:BD500").Copy _
Workbooks(destination).Worksheets("Sheet1").Range("A6")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.