[英]Excel VBA: copy lots of columns
I´d like to copy all data from a Sheet to another sheet of another new Excel file. 我想将工作表中的所有数据复制到另一个新Excel文件的工作表中。 I have tried this:
我已经试过了:
Set wkb = Workbooks.Add
wkb.SaveAs myNewFile
ThisWorkbook.Worksheets("Sheet 2").Activate
Set Ticker = ThisWorkbook.Worksheets("Sheet 2").Range("A1").CurrentRegion
Ticker.Copy
wkb.Worksheets(1).Activate
Cells(1, 1).PasteSpecial xlPasteAll
wkb.Save
wkb.Close
The problem I´ve found is that it won´t work when there are a great amount of columns (for instance, from A to OV). 我发现的问题是,当有大量列(例如,从A到OV)时,它将无法工作。 Do you know other way to to this?
您知道其他方式吗?
You could skip the clipboard altogether: 您可以完全跳过剪贴板:
Set wkb = Workbooks.Add
copyAddress$ = ThisWorkbook.Worksheets("Sheet 2").Range("A1").CurrentRegion.Address
With wkb
.SaveAs myNewFile
.Sheets(1).Range(copyAddress).Value = ThisWorkbook.Worksheets("Sheet 2").Range(copyAddress).Value
.Save
.Close True '// Assuming you would want to save changes
End With
Or you could just copy the entire sheet: 或者,您可以复制整个工作表:
Set wkb = Workbooks.Add
ThisWorkbook.Sheets("Sheet 2").Copy Before:=wkb.Sheets(1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.