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..求解
展开
 我来答
百无生
推荐于2020-03-13 · TA获得超过2214个赞
知道大有可为答主
回答量:2150
采纳率:80%
帮助的人:618万
展开全部
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
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式