分享

excel工作表拆分

 360word 2020-04-09

Sub SaveAs()

    On Error Resume Next

    Dim FolderPath As String, FolderName As String, BN As String

    Dim ReturnValue As Integer

    BN = ActiveWorkbook.Name

    FolderPath = ThisWorkbook.Path

    FolderName = Mid(BN, 1, InStrRev(BN, ".", Len(BN)) - 1)

    Dim MyFile As Object

    Set MyFile = CreateObject("Scripting.FileSystemObject")

    If MyFile.folderexists(FolderPath & "\" & FolderName & "-Saved") Then

        ReturnValue = MsgBox("文件夹已存在,是否更新内容?", vbOKCancel, "Caution!")

        If ReturnValue = 2 Then Exit Sub

    Else

        MyFile.CreateFolder (FolderPath & "\" & FolderName & "-Saved")

        Set MyFile = Nothing

    End If

    Application.ScreenUpdating = False

    Application.DisplayAlerts = False

    Dim i As Integer

    For i = 1 To Sheets.Count

        Set Wk = Workbooks.Add

        Workbooks(BN).Sheets(i).Copy before:=Wk.Worksheets("Sheet1")

        Wk.SaveAs FolderPath & "\" & FolderName & "-Saved\" & ThisWorkbook.Sheets(i).Name

        Wk.Close

    Next i

    Application.DisplayAlerts = True

    Application.ScreenUpdating = True

End Sub

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多