How to copy the contents of the active sheet to a new workbook?

后端 未结 4 1950
星月不相逢
星月不相逢 2020-12-06 17:37

I\'m trying to copy the contents of the active sheet to a new workbook.

Sub new_workbook()

    Dim ExtBk As Workbook
    Dim ExtFile As String

    Columns(         


        
4条回答
  •  忘掉有多难
    2020-12-06 18:16

    If you are copying the entire area, then copy the worksheets:

    Worksheets("Sheet1").Copy Workbooks(2).Worksheets(1)
    

    If it copies a couple of columns that you don't need then you could delete this afterwards.

    If you are copying from .xlsx to .xls then you'll need to use Copy/Paste:

    Worksheets("Sheet1").UsedRange.Copy Workbooks(2).Worksheets(1).Range("A1")
    

    If pasting values is required:

    Workbooks(2).Worksheets(1).UsedRange.Copy
    Workbooks(2).Worksheets(1).Range("A1").PasteSpecial xlPasteValues
    

    Be aware that UsedRange won't start from A1 unless this cell has some content. In which case, you'll have to define a Range object that starts at A1 and extends to the last used cell.

提交回复
热议问题