下面的代码执行第一次的时候没有问题
但是第二次执行ExcelSheet.Range("A2:J10").Sort... 代码的时候
报错:"应用程序定义或对象定义错误"On Error GoTo Err_lbl
Set ExcelApp = CreateObject("Excel.Application") '创建EXCEL对象
Set ExcelBook = ExcelApp.Workbooks.Open(strPath)
Set ExcelSheet = ExcelBook.Worksheets(1) '生成凭证后的ID ExcelSheet.Range("A2:J10").Sort Key1:=Range("J2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, SortMethod _
:=xlPinYin, DataOption1:=xlSortNormal ExcelBook.SaveAs ("C:\AAAAAAAA.xls")
Err_lbl:
strGroup = Err.Description
ExcelBook.Close (True)
ExcelApp.Quit
Set ExcelBook = Nothing
Set ExcelApp = Nothing
但是第二次执行ExcelSheet.Range("A2:J10").Sort... 代码的时候
报错:"应用程序定义或对象定义错误"On Error GoTo Err_lbl
Set ExcelApp = CreateObject("Excel.Application") '创建EXCEL对象
Set ExcelBook = ExcelApp.Workbooks.Open(strPath)
Set ExcelSheet = ExcelBook.Worksheets(1) '生成凭证后的ID ExcelSheet.Range("A2:J10").Sort Key1:=Range("J2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, SortMethod _
:=xlPinYin, DataOption1:=xlSortNormal ExcelBook.SaveAs ("C:\AAAAAAAA.xls")
Err_lbl:
strGroup = Err.Description
ExcelBook.Close (True)
ExcelApp.Quit
Set ExcelBook = Nothing
Set ExcelApp = Nothing
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货