使用 Visual Studio .NET 客户端执行自动化功能后不退出 Office 应用程序 代码
2008-09-10 21:44
711 查看
1.
vb.net
Imports Microsoft.Office.Interop
Private Sub NAR(ByVal o As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(o)
Catch
Finally
o = Nothing
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim oApp As New Excel.Application()
Dim oBooks As Excel.Workbooks = oApp.Workbooks
Dim oBook As Excel.Workbook = oBooks.Add
Dim oSheet As Excel.Worksheet = oApp.ActiveSheet
NAR(oSheet)
oBook.Close(False)
NAR(oBook)
NAR(oBooks)
oApp.Quit()
NAR(oApp)
GC.Collect()
Debug.WriteLine("SleepingCode
private void NAR(object o)
{
try
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(o);
}
catch {}
finally
{
o = null;
}
}
exBook.Close(DBNull.Value, DBNull.Value, DBNull.Value)
exApp.Workbooks.Close()
exApp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(exApp)
System.Runtime.InteropServices.Marshal.ReleaseComObject(exSheet)
System.Runtime.InteropServices.Marshal.ReleaseComObject(exBook)
exApp = Nothing
exBook = Nothing
exSheet = Nothing
GC.Collect()
参考文章:http://support.microsoft.com/?id=317109
vb.net
Imports Microsoft.Office.Interop
Private Sub NAR(ByVal o As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(o)
Catch
Finally
o = Nothing
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim oApp As New Excel.Application()
Dim oBooks As Excel.Workbooks = oApp.Workbooks
Dim oBook As Excel.Workbook = oBooks.Add
Dim oSheet As Excel.Worksheet = oApp.ActiveSheet
NAR(oSheet)
oBook.Close(False)
NAR(oBook)
NAR(oBooks)
oApp.Quit()
NAR(oApp)
GC.Collect()
Debug.WriteLine("SleepingCode
private void NAR(object o)
{
try
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(o);
}
catch {}
finally
{
o = null;
}
}
exBook.Close(DBNull.Value, DBNull.Value, DBNull.Value)
exApp.Workbooks.Close()
exApp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(exApp)
System.Runtime.InteropServices.Marshal.ReleaseComObject(exSheet)
System.Runtime.InteropServices.Marshal.ReleaseComObject(exBook)
exApp = Nothing
exBook = Nothing
exSheet = Nothing
GC.Collect()
参考文章:http://support.microsoft.com/?id=317109
相关文章推荐
- 使用 Visual Studio .NET 客户端执行自动化功能后不退出 Office 应用程序
- 使用 Visual Studio .NET 客户端执行自动化功能后不退出 Office 应用程序
- 使用 Visual Studio .NET 客户端执行自动化功能后不退出 Office 应用程序
- 使用 Visual Studio .NET 客户端执行自动化功能后不退出 Office 应用程序
- Office application does not quit after automation from Visual Studio .NET client(从VS.NET客户端自动化后,Office应用程序不退出)
- VisualStudio.NET 或 Visual Studio 2005 客户端应用程序无法捕获 Office Spreadsheet 11.0 ActiveX 控件通过引发事件
- 使用Visual Studio .NET创建控制台应用程序
- Visual Studio .NET使用技巧手册读书笔记之编写代码
- 在 Visual Studio .NET 中使用 SQL Server 2000 创建数据库应用程序(1)
- 使用VS2010代码分析功能增强ASP.NET应用程序安全
- 70-316 使用Microsoft Visual C# .NET and Microsoft Visual Studio .NET 开发及实现基于Windows的应用程序 考点整理
- 使用Visual Studio Code创建第一个ASP.NET Core应用程序
- 从 ASP.NET 应用程序调用 Microsoft Visual Basic 6.0 DLL 时,使用 Microsoft Visual Studio .NET 本机调试器调试它
- 使用 Microsoft Office 将 Visual Studio .NET 的强大功能引入业务解决方案的建立[转]
- Visual C# .NET 中使用自动化运行 Office 宏
- 一起谈.NET技术,使用VS2010代码分析功能增强ASP.NET应用程序安全
- 使用 Visual C++ .NET 和 MFC 关闭 Office 应用程序显示的对话框
- 使用更精简的代码保证 ASP.NET 应用程序的安全
- 打开项目时提示如下错误:Visual Studio .NET 无法创建应用程序...
- Visual Studio .NET 无法创建或打开应用程序。问题很可能是因为本地WEB本地服务器上没有安装所需的组件。请运行Visual Studio .NET安装程序并添加WEB开发组件