将工作表复制并保存到新工作簿

时间:2015-10-12 14:04:55

标签: excel-vba save vba excel

嗨我有下面的代码,但每次运行时都会出现一个消息框,其中显示“代码执行已被中断”。当我按下继续时,这是通过但是我想要一个没有消息框的方法。请参阅下面的代码。

Sub SAVEProcImpReview()
    Application.DisplayAlerts = False
        Dim wb1 As Workbook
        Set wb1 = Workbooks("Action Plan Template")
        ThisWorkbook.Sheets("Proc Imp Review").Copy
        ActiveWorkbook.SaveAs "T:\Departments\Purchasing\Data\Vendor Management\Procurement Implementation\Procurement Review's\Proc Imp Review Week " & Format(Now, "ww") & " " & Year(Date) & " .xlsx"
        Workbooks("Proc Imp Review Week " & Format(Now, "ww") & " " & Year(Date) & " .xlsx").Close
    Application.DisplayAlerts = True
    wb1.Activate
End Sub

1 个答案:

答案 0 :(得分:0)

你可以试试这个,经过一些小修改我不会遇到你遇到的问题:

Sub SAVEProcImpReview()
    Application.DisplayAlerts = False
        Dim wb1 As Workbook
        Dim newWB As Workbook
        Set wb1 = Workbooks("Action Plan Template")
        wb1.Sheets("Proc Imp Review").Copy
        Set newWB = ActiveWorkbook
        newWB.SaveAs .SaveAs "T:\Departments\Purchasing\Data\Vendor Management\Procurement Implementation\Procurement Review's\Proc Imp Review Week " & Format(Now, "ww") & " " & Year(Date) & " .xlsx"
        newWB.Close
    Application.DisplayAlerts = True
    wb1.Activate
End Sub