帮你加了个防错的。 Private Sub CommandButton1_Click() on error resume next Dim c As String Dim NewBook As Workbook Dim NewSheet As Worksheet Dim OldBook As Workbook Set OldBook = ThisWorkbook imonth = Range("R12").Value imonth1 = Range("R11").Value imonth2 = Range("R13").Value '新建工作簿 Set NewBook = Workbooks.Add(xlWBATWorksheet) Set NewSheet = NewBook.Sheets(1) NewSheet.Name = "Amulee" OldBook.Sheets(Array("Sheet1", "Sheet2")).Copy Before:=NewSheet Application.DisplayAlerts = False NewSheet.Delete Application.DisplayAlerts = True If Dir("D:\" & (imonth1) & "年" & imonth & "月", vbDirectory) = "" Then MkDir ("D:\" & (imonth1) & "年" & imonth & "月") End If If Dir("D:\" & (imonth1) & "年" & imonth & "月" & "\" & imonth & "月" & (imonth2) & "日", vbDirectory) = "" Then MkDir "D:\" & (imonth1) & "年" & imonth & "月" & "\" & imonth & "月" & (imonth2) & "日" End If If Dir("D:\" & (imonth1) & "年" & imonth & "月" & "\" & imonth & "月" & (imonth2) & "日" & "\" & Range("k3") & ".xls") = "" Then NewBook.SaveCopyAs Filename:=("D:\" & (imonth1) & "年" & imonth & "月" & "\" & (imonth & "月" & (imonth2) & "日") & "\" & Range("k3") & ".xls") Else t = MsgBox("是否覆盖?", vbYesNo) If t = vbYes Then NewBook.SaveCopyAs Filename:=("D:\" & (imonth1) & "年" & imonth & "月" & "\" & (imonth & "月" & (imonth2) & "日") & "\" & Range("k3") & ".xls") MsgBox "文件已另存到共享区" End If End If NewBook.Close False End Sub |