用VB6编的一程序是操作Word文档的,主过程按钮的前面代码是:Private Sub Command1_Click()Dim wdApp As Word.Application
Dim myWdDoc As Word.Document
Set wdApp = New Word.Application
 wdApp.Activate
读入文件到Word中
  Set myWdDoc = wdApp.Documents.Open(Filename:=Form1.Filename.Text, Format:=wdOpenFormatText)
……
在主过程中还用
Call XXX
调用若干子过程为退出程序,又做了一个按钮,
Private Sub Quit_Click()
    Unload Me
End Sub由于Command1_Click中的代码很长(还另有子过程),实际上,按了Command1按钮后,程序运行过程中,如按Quit按钮是不能退出Command1的(当然,调用的Word也在运行中),只能在Command1运行完后再按Quit按钮才能退出程序,现在我想在Command1运行的任意时刻一按Quit按钮能使Command1运行停止(也要同时终止调用的Word并退出Word),不知怎么实现?

解决方案 »

  1.   

     Private Sub Command1_Click()
    'your code
    doevents
    end sub
      

  2.   

    如果存在一个很大的子过程确实很麻烦
    程序End后 进程还在运行.
    如果子程序是个很大的循环,可以这样:
    Dim Isesc as boolean
    sub commamd1_click
    do untile IsEsc=true
    ...
    DoEvents
    loop
    end sub
    sub command2_click
    wdApp.quit
    IsEsc=true
    end sub
      

  3.   

    不好意思 刚才until打错了.为什么我不能修改我自己的回复?
    Dim isEsc as boolean 
    sub commamd1_click 
    do until isEsc=true 
    ... 
    DoEvents 
    loop 
    end sub 
    sub command2_click 
    wdApp.quit 
    isEsc=true 
    end sub
      

  4.   

    你可以到这里看看我的"小型记事本文档"
    http://download.csdn.net/source/800093