小弟公司做一个程序,要频繁导入EXCEL数据,但每导入一次进程都开一个EXCEL进程,这样多导入几次计算机不很慢慢了,程序也不稳定了,求大哥帮我写一下怎么完全关闭EXCEL进程。

解决方案 »

  1.   

    你调用EXCEL的时候就有个quite方法啊
    直接调用即可
      

  2.   

    我们就是要EXCEL里面的数据,。你说的这个方法我们没有用到我也不明白你说的是什么意思,但还是谢谢你了
      

  3.   

    Dim xlsApp As EXCEL.Application
        Dim xlsWorkBook As EXCEL.Workbook
        Dim xlsWorksheet As EXCEL.WorksheetSet xlsApp = CreateObject("Excel.Application")
        Set xlsWorkBook = xlsApp.Workbooks.Add
        Set xlsWorksheet = xlsWorkBook.Worksheets(1)关闭时
    Set xlsWorkBook = Nothing
        Set xlsWorksheet = Nothing
        xlsApp.Quit
        Set xlsApp = Nothing
    Set xlsheet = Nothing
      

  4.   

    上面最后一行去掉
    如果想直接杀死进程里的EXCEL用下面这种Public Sub subKillProcess(ByVal strProcess As String)    Dim strComputer As String
        Dim objWMIService As Object
        Dim colProcessList
        Dim objProcess As Object
        
        On Error Resume Next
        
        strComputer = "."
        Set objWMIService = GetObject("winmgmts:" _
            & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    '        strProcess = "Excel.exe"
        Set colProcessList = objWMIService.ExecQuery _
            ("Select * from Win32_Process Where Name = '" & strProcess & "'")
        For Each objProcess In colProcessList
            objProcess.Terminate
        Next
        
    End Sub
    '调用
    Call subKillProcess("Excel.exe")
      

  5.   

    谢谢几位了,我知道怎么关了,但我要关就都关了,不用我们这个程序的EXCEL也关了,我就想打开那个关那个啊,不知道怎么判断呢,
      

  6.   

    1.在導入excel數據時,盡量改用ado的方式打開,速度和效率會更快
    Set mConn = New ADODB.Connection
        With mConn
            .CursorLocation = adUseClient
            .Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mPath & "\yourexecl.xls;Extended Properties=""Excel 8.0;"""
        End With
        Set mRsRead = New ADODB.Recordset
        mRsRead.CursorLocation = adUseClient
        
        mRsRead.Open "select  F1,F2,F3,F4  from [yourexeclsheet$]  ", mConn, adOpenStatic, adLockOptimistic, adCmdText
    2.在建立一個APP后,可以根據Workbooks(i).FullName來判斷是哪一個excel
    3.關閉excel的順序如下:
    Set ExcelSheet = Nothing
    BookWork.Close
    Set BookWork= Nothing
    Set ExcelApp= Nothing
      

  7.   

    直接用ado 方式访问xls 文件
    要比用excel 程序快的多