注册 登录
编程论坛 VB6论坛

这条语句执行出错

chen3bing 发布于 2019-07-26 11:12, 1554 次点击
Private Sub Command1_Click()
Dim i As Long
XlSheet.application.statusbar = "兴趣是最好的老师"
Do
    For i = 1 To 100000
        DoEvents
    Next
    XlSheet.application.statusbar = Right(XlSheet.application.statusbar, Len(XlSheet.application.statusbar) - 1) _
        & Left(XlSheet.application.statusbar, 1)
    If XlApp.Quit Then Exit Do          这句出错      
Loop
End Sub
我向用VB控制EXCEL表格状态栏显示滚动文字,以上是代码。
我想关闭EXCEL后,退出DO LOOP循环,可是出错
只有本站会员才能查看附件,请 登录

如何解决?谢谢!
5 回复
#2
chen3bing2019-07-28 15:44
搞定了。
Private Sub Command1_Click()
Dim i As Long
XlSheet.Application.StatusBar = "兴趣是最好的老师"
On Error GoTo lblErr
Do
    For i = 1 To 100000
        DoEvents
    Next
    XlSheet.Application.StatusBar = Right(XlSheet.Application.StatusBar, Len(XlSheet.Application.StatusBar) - 1) _
        & Left(XlSheet.Application.StatusBar, 1)
    'If XlApp.Application = Nothing Then Exit Do
Loop
lblErr:
    MsgBox "Excel已关闭"
End Sub
#3
风吹过b2019-07-28 19:00
If XlApp.Application is Nothing Then Exit Do
好像可以这样用。
手头上这个电脑上没VB了,没办法测试。
#4
chen3bing2019-07-28 19:18
回复 3楼 风吹过b
不行,有错误。
只有本站会员才能查看附件,请 登录
#5
风吹过b2019-07-28 21:30
回头明天测试一下。
按理来有状态可以检测的,一般情况下,不要使用 错误捕捉 去处理正常的程序。

要么就是可能就是 只需要测试
XlApp is Nothing

--------------------
运行这报错,点调试,然后点菜单,窗口,本地窗口 ,检查这个对象是什么状态,写什么判断。

#6
chen3bing2019-07-29 08:17
谢谢!你帮我测试一下。
1