查询结果二次输出提示“method 'cells' of object '_global'failed”,怎么办?
If rs.EOF = True Then
MsgBox "暂时没有符合您要求的数据", , "提示"
Else
For ii = 1 To rs.Fields.Count
Cells(1, ii).Value = rs.Fields(ii - 1).name
Next ii
rs.MoveFirst
Do While Not rs.EOF
jj = jj + 1
For ii = 1 To rs.Fields.Count
Cells(jj + 1, ii).Value = rs.Fields(ii - 1).Value
If Cells(jj, 1).Value <> LastValue Then
LastValue = Cells(jj, 1).Value
ColorIndex = ColorIndex + 1
End If
Range(Cells(jj + 1, 1), Cells(jj, 4)).Select
Selection.Interior.ColorIndex = ColorIndex
Next ii
rs.MoveNext
Loop
jj = 0
End If
xexcel.Visible = True
Set xworkbool = Nothing
Set xexcel = Nothing
上面这段代码是我用来实现查询结果输出的。当我第一次点击输出按钮时,没有问题,但如果我不退出程序,将输出的表关闭后,换一种查询方法输出时,就会提示“method 'cells' of object '_global'failed”,我应该怎么改这段代码?
我的查询语句是没有问题的。
谢谢!
还有就是我生成的excel表,虽然我把它关闭了。但是,在进程里还是有的,这是什么原因呢?