vb导出到Excel,导出一次后,必须重新启动程序才能再执行,为什么?
For i = 1 To Adodc1.Recordset.RecordCount
For j = 1 To Adodc1.Recordset.Fields.Count
mysheet.Cells(i , j ) = Adodc1.Recordset.Fields.Item(j ).Value
Next j
Adodc1.Recordset.MoveNext
Next i
myexcel.Visible = True
以上代码可以正确执行,可是导入一次后,就不行了,关闭程序,在运行则可以,请问为什么,怎么改呢,谢谢
[解决办法]
with Adodc1.Recordset
if .recordcount>0 then
.movefirst
For i = 1 To .RecordCount
For j = 1 To Adodc1.Recordset.Fields.Count
mysheet.Cells(i , j ) = .Fields.Item(j ).Value
Next j
.MoveNext
Next i
myexcel.Visible = True
end if
end with