工程无故自动退出,请教
VB6小白请教。我写了一段将listview数据导出到新建excel文件的代码。在执行过程中发现,点击按钮后,整个工程会自动关闭,且没有任何报错。这时候如果打开wps,会看到刚刚新建的文件没有保存。这是为什么呢,疑惑中。程序代码:
Private Sub Command3_Click() Dim xla As Excel.Application 'Excel对象 Dim xlb As Excel.Workbook '工作簿 Dim xlss As Excel.Worksheet '工作表 Dim xlrange As Excel.Range Dim i As Long Dim j As Long Dim savepath As String Set xla = CreateObject("excel.application") '第一层 Set xlb = xlApp.Workbooks.Add Set xlss = xlb.Worksheets(1) xla.Visible = False j = 2 For i = ListView1.ListItems.Count To 1 Step -1 xlss.Cells(j, 1) = ListView1.ListItems(i).Text xlss.Cells(j, 2) = ListView1.ListItems(i).ListSubItems(1) xlss.Cells(j, 3) = ListView1.ListItems(i).ListSubItems(2) xlss.Cells(j, 4) = ListView1.ListItems(i).ListSubItems(3) xlss.Cells(j, 5) = ListView1.ListItems(i).ListSubItems(4) xlss.Cells(j, 6) = ListView1.ListItems(i).ListSubItems(5) j = j + 1 Next 'xlb.Sheets(1).Range("a1") = "新建成功" savepath = "D:\" xlb.SaveAs savepath & "\领取记录.xls" xlb.Close (True) xla.Quit '关闭EXCEL Set xla = Nothing '释放EXCEL对象 End Sub