VB程序中怎么样结束EXCEL进程

来源:互联网 发布:中华文明没有中断知乎 编辑:程序博客网 时间:2024/04/28 23:40

EXL = CreateObject("Excel.Application") 

 Try  

       EXL = GetObject(, "Excel.Application")    

    Catch ex As Exception   

         If EXL Is Nothing Then      

              EXL = New Excel.Application       

     End If      

  End Try  

 System.Runtime.InteropServices.Marshal.ReleaseComObject(worksheets);

System.Runtime.InteropServices.Marshal.ReleaseComObject(worksheet);

System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);

System.Runtime.InteropServices.Marshal.ReleaseComObject(range);

worksheets=null

 worksheet=null

excelApp=null

range=null

把操作Excel文件用到的对象实例全部释放。然后资源回收!

 GC.Collect()

原创粉丝点击