VBA运行时错误1004代码..方法saveas作用于对象_workbook时失败(2010版excel)
Subsavetofile()Application.ScreenUpdating=FalseDimfolderAsStringfolder=ThisWorkbook.P...
Sub savetofile()Application.ScreenUpdating = FalseDim folder As Stringfolder = ThisWorkbook.Path & "\班级成绩表"If Len(Dir(folder, vbDirectory)) = 0 Then MkDir folderDim sht As WorksheetFor Each sht In Worksheets sht.Copy ActiveWorkbook.SaveAs folder & "\" & sht.Name & ".xls" ActiveWorkbook.CloseNextApplication.ScreenUpdating = TrueEnd Sub
我想把成绩表,七(1)班至七(9)班的每个工作表单独变成一个工作簿.程序只生成一个,就报错1004..求解 展开
我想把成绩表,七(1)班至七(9)班的每个工作表单独变成一个工作簿.程序只生成一个,就报错1004..求解 展开
1个回答
展开全部
Sub savetofile()
Application.ScreenUpdating = False
on error resume next '忽略错误,继续执行
Dim folder As String
folder = ThisWorkbook.Path & "\班级成绩表"
If Len(Dir(folder, vbDirectory)) = 0 Then MkDir folder
Dim sht As Worksheet
For Each sht In thisworkbook.Worksheets
if sht.name<>"成绩表" then '判断表名
sht.Copy
ActiveWorkbook.SaveAs folder & "\" & sht.Name & ".xlsx"
ActiveWorkbook.Close
end if
Next
Application.ScreenUpdating = True
End Sub
Application.ScreenUpdating = False
on error resume next '忽略错误,继续执行
Dim folder As String
folder = ThisWorkbook.Path & "\班级成绩表"
If Len(Dir(folder, vbDirectory)) = 0 Then MkDir folder
Dim sht As Worksheet
For Each sht In thisworkbook.Worksheets
if sht.name<>"成绩表" then '判断表名
sht.Copy
ActiveWorkbook.SaveAs folder & "\" & sht.Name & ".xlsx"
ActiveWorkbook.Close
end if
Next
Application.ScreenUpdating = True
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询