VB6导出EXCEL 排序的问题下面的代码执行第一次的时候没有问题但是第二次执行ExcelSheet.Range(A2:J10).S
VB6导出EXCEL 排序的问题
下面的代码执行第一次的时候没有问题
但是第二次执行ExcelSheet.Range("A2:J10").Sort... 代码的时候
报错:"应用程序定义或对象定义错误"
- VB code
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[解决办法]
帮顶关注一下!
[解决办法]
用完对象要记得关闭和销毁, 否则第二次可能会有问题.
[解决办法]
