如何将工作表中的工作表复制到新的打开的工作簿并根据列表重命名新的工作簿

时间:2019-03-19 02:53:54

标签: excel vba

Sub ExportSheets()

    Dim wb As Workbook
    Dim x As Long
    Dim last As Long
    Dim y As Long

    last = Workbooks("Master").Worksheets("Master").Cells(Rows.Count, "A").End(xlUp).Row
    last1 = Workbooks("Master").Worksheets("Master").Cells(Rows.Count, "B").End(xlUp).Row


    Set wb = ActiveWorkbook
    Sheets(Array(2, 3)).Copy

    For x = 2 To last
        Workbooks("Master").Worksheets("Master").Cells(x, 1).Copy
        ActiveWorkbook.Worksheets(1).Cells(1, 1).PasteSpecial Paste:=xlPasteFormulas

        'For y = 2 To last1
            'ActiveWorkbook.SaveAs "C:\Users\nkelaniy\Desktop\" & Workbooks("Master").Worksheets("Master").Cells(y, 2) & ".xlsx"
            ActiveWorkbook.SaveAs "C:\Users\nkelaniy\Desktop\" & ActiveWorkbook.Worksheets(1).Cells(1, 1) & ".xlsx"
        'Next
    Next

End Sub

我要从主工作簿复制两张纸到新工作簿,然后根据主工作簿主纸清单重新命名并保存。第二个列表也会复制每个新工作簿的第一个工作表A1单元。

它工作正常,但是当我循环播放根据list重命名时。正在替换excel消息并错误地复制了数据。

请帮助

0 个答案:

没有答案