我在cmd_print的按钮控件的单击事件里写下这么一段话:    cmd_print.Visible = False
    Me.Refresh
    Dim Irow, Icol As Integer
    Dim Irowcount, Icolcount As Integer
    Dim Fieldlen() '存字段长度值
    Dim xlApp As Excel.Application
    Dim xlBook As Excel.Workbook
    Dim xlSheet As Excel.Worksheet
    Set xlApp = CreateObject("Excel.Application")
    Set xlBook = xlApp.Workbooks.Add
    Set xlSheet = xlBook.Worksheets(1)
    xlSheet.Cells(1, 1).Value = "def"
    xlSheet.SaveAs ("d:\abc.xls")
    Set xlApp = Nothing
    cmd_print.Visible = True
    Me.Refresh
问题一:
结果发现运行后在系统进程里一直有个Excel的进程,请问哪位大虾能告诉我,怎样在程序里就杀死那个Excel进程吗?不然的话,用户如果要再在程序外打开那个d:\abc.xls的话,就死都打不开,除非在任务管理器里先终止那个Excel的进程。
问题二:
如果用户在按这个按钮的时候如果是双击的话,我发现就算我这么写,也会运行两次,
 cmd_print.Visible = False
    Me.Refresh
这个又要怎么解决呀?不过我估计把问题一解决了的话,问题二也就差不多了。
请大家帮个忙,先在这里谢过大家了。

解决方案 »

  1.   

    这一句——
        Set xlApp = Nothing
    前加上——
        xlApp.quit
      

  2.   

    1、你在程序結束後,必須顯式地釋放所有Excel對象:
    set xlsSheet = nothing
    set xlsBook = nothing
    set xlsApp = nothing2、命令按紐隻有單擊事件,所以如果你按了兩下,那當然會執行相同的操作兩次。
      

  3.   

    问题1遇到过……搞了2周,发现问题出在给EXCEL的CELL赋值的语句上……————————————————————————————————Private Sub cmdPrint_Click()    Dim intPrint As Integer
        Dim xlApp As New Excel.Application
        Dim xlBook As New Excel.Workbook
        Dim xlSheet As New Excel.Worksheet    Set xlApp = Nothing
        Set xlBook = Nothing
        Set xlSheet = Nothing
      
            intPrint = MsgBox("Be sure to print this record?", vbYesNo)
            If intPrint = 6 Then
                Set xlApp = CreateObject("Excel.Application")
                Set xlBook = xlApp.Workbooks.Open(App.Path & "\temp.xls")
                Set xlSheet = xlBook.Worksheets("Sheet1")
                
                xlSheet.Range("C3").Value = "test……"   
                 
                xlApp.Application.Visible = True    
                xlSheet.PrintPreview                '预览
                xlApp.DisplayAlerts = False         '退出时不提示保存
                xlBook.Close
                xlApp.Quit                          
                xlApp.DisplayAlerts = True          
                Set xlSheet = Nothing
                Set xlBook = Nothing
                Set xlApp = Nothing
                MsgBox "Job done ..."
            End If    End Sub————————————————————————————————————以上语句调试通过,在Set xlApp = Nothing后EXCEL进程消失……但xlSheet.Range("C3").Value = "test……"替换为复杂的循环赋值后,就出现你说的问题1了……最后是把复杂的循环赋值简化后解决的问题……只是治标没治本,不知道为何给CELL复杂循环赋值会让其一直驻留进程……
      

  4.   

    xinliangyu(yxl)的解答+leayh(云卷云舒)的解答=我的解答
      

  5.   

    谢谢大家啊,我现在用了xlApp.Quit 方法就能解决了。