如何关闭通过添加 doc.InlineShapes.AddOLEObject 创建的实例

How to close instance created by adding doc.InlineShapes.AddOLEObject

我正在通过 doc.InlineShapes.AddOLEObject 将 word 文档插入到 word 文档中。

doc.InlineShapes.AddOLEObject(System.Type.Missing, filename, true, false, System.Type.Missing, System.Type.Missing, System.Type.Missing, range);

它插入了嵌入文档,但关闭主word文件后,WINWORD.EXE进程仍在运行。如何解决这个问题呢。谁能帮帮我?

我相信这个问题与不释放代码中的底层 COM 对象有关。使用 System.Runtime.InteropServices.Marshal.ReleaseComObject to release a Word object when you have finished using it. Then set a variable to Nothing in Visual Basic (null in C#) to release the reference to the object. See Office application does not quit after automation from Visual Studio .NET client 获取有关该问题的更多信息。