Copy an Entire Worksheet - Keep Same Formatting

烂漫一生 提交于 2019-12-13 02:21:06

问题


I would like to copy worksheet "Trial Sheet" located in workbook "Trial Data.xlsx" to a seaparate workbook called "Copy Worksheet". I would like to keep the format (column width, zoom, etc.), be able to copy the worksheet without having to open the "Trial Data" workbook which the macro doesn't seem to do.

The macro I recorded is as follows.

Sub worksheet_copy()


Windows("Trial Data.xlsx").Activate
Cells.Select
Selection.Copy
Windows("Copy Worksheet.xlsm").Activate
Cells.Select
ActiveSheet.Paste

End Sub

I came across a previous answer (Copy an entire worksheet to a new worksheet in Excel 2010) but don't understand how to modify for my specific files without an error. Any help would be greatly appreciated.


回答1:


This should give you direction:

Sub worksheet_copy()

    Thisworkbook.worksheets("SheetName").Range("A:AB").Copy  _
        destination:= workbooks("Copy Worksheet.xlsm").worksheets(1).cells(1,1)

End Sub

Why using those Windows() stuff ? Be clear: use Workbook for workbooks, Worksheet for...worksheets.
And stop using those slow and unnecessary .Activate !



来源:https://stackoverflow.com/questions/18643867/copy-an-entire-worksheet-keep-same-formatting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!