質問

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.

役に立ちましたか?

解決

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 !

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top