VS 2008开放Word文档 - 内存错误

时间:2008-12-11 14:13:01

标签: visual-studio-2008 automation ms-word ms-office

我正在执行以下代码,在vs2003(1.1)中运行良好,但似乎已经决定现在我正在使用vs2008(2.0 / 3.5):

Dim wordApp As Microsoft.Office.Interop.Word.Application
Dim wordDoc As Microsoft.Office.Interop.Word.Document

missing = System.Reflection.Missing.Value
wordApp = New Microsoft.Office.Interop.Word.Application()
Dim wordfile As Object
wordfile = "" ' path and file name goes here

wordDoc = wordApp.Documents.Open(wordfile, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing)

尝试打开时抛出的错误是: “试图读取或写入受保护的内存。这通常表明其他内存已损坏。”

有没有人知道如何纠正这个问题?

1 个答案:

答案 0 :(得分:0)

要检查的事项:

  • Word安装是理智的(通过双击工作打开一个简单的文档)?
  • 没有运行防病毒工具(也许该工具对COM自动化很严格)?

还有一句话:由于您使用的是VB.Net,因此无需编写所有“缺失”参数,以下代码看起来更简单:

Dim wordApp As Microsoft.Office.Interop.Word.Application
Dim wordDoc As Microsoft.Office.Interop.Word.Document
Dim wordfile As String

wordApp = New Microsoft.Office.Interop.Word.Application
wordfile = "" ' path and file name goes here

wordDoc = wordApp.Documents.Open(wordfile)