使用VBA宏通过介绍性标签将每个Excel工作表另存为单独的工作簿

时间:2018-12-07 17:16:50

标签: excel vba split copy add

我有一个包含许多标签的电子表格。我想将每个标签复制到自己的文件中,可以使用下面的代码完成

我的问题是在每本新工作簿中都添加了说明表。我在原始工作簿中有一个说明表。

您的帮助将不胜感激。

Sub Splitbook()
MyPath = ThisWorkbook.Path
For Each sht In ThisWorkbook.Sheets
sht.Copy
ActiveSheet.Cells.Copy
ActiveSheet.Cells.PasteSpecial Paste:=xlPasteValues
ActiveSheet.Cells.PasteSpecial Paste:=xlPasteFormats
ActiveWorkbook.SaveAs _
Filename:=MyPath & "\" & sht.Name & " SP Signoff.xlsx"
ActiveWorkbook.Close savechanges:=False
Next sht
End Sub

1 个答案:

答案 0 :(得分:0)

Sub Splitbook()

    Dim wkb As Workbook
    Dim wks As Worksheet, sht As Worksheet
    Dim strPath As String

    Set wkb = ThisWorkbook
    Set wks = Sheets("Instructions")

    strPath = wkb.Path

    For Each sht In wkb.Sheets
        If sht.Name <> "Instructions" Then
            sht.Copy

            With ActiveSheet
                .Cells.Copy
                .Cells.PasteSpecial Paste:=xlPasteValues
                .Cells.PasteSpecial Paste:=xlPasteFormats
            End With

            wks.Copy Before:=ActiveWorkbook.Sheets(1)

            ActiveWorkbook.SaveAs _
            Filename:=MyPath & "\" & sht.Name & " SP Signoff.xlsx"
            ActiveWorkbook.Close savechanges:=False
        End If

    Next

End Sub