VBA 拆分表时保存路径用变量时提示”下标越界“,是怎么回事?
展开全部
代码会认为 新建的 Workbook是 Thisworkbook
拆分工作薄 不用这么写
Sub 拆分()Application.ScreenUpdating = Falseb = Sheets.CountFor i = 1 To bSheets(i).Copya = ThisWorkbook.Worksheets(i).NameWith ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & "\" & a & ".xls".Close TrueEnd WithNext iApplication.ScreenUpdating = trueEnd Sub
拆分工作薄 不用这么写
Sub 拆分()Application.ScreenUpdating = Falseb = Sheets.CountFor i = 1 To bSheets(i).Copya = ThisWorkbook.Worksheets(i).NameWith ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & "\" & a & ".xls".Close TrueEnd WithNext iApplication.ScreenUpdating = trueEnd Sub
追问
为什么第二张图的写法运行起来没有问题?这两个写法只有保存路径”path & "\" & xxx & ".xlsx" 在xxx处不同
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询