views:

961

answers:

1

I am executing the following code that worked fine in a vs2003(1.1) but seems to have decided otherwise now that I'm using 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)

The error thrown when the Open is attempted is : "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

Does anyone have any idea how to correct this?

A: 

Things to check:

  • Word installation is sane (does opening a simple document via double-click work)?
  • no anti-virus tool is running (maybe the tool is strict about COM automation)?

And another remark: Since you are using VB.Net there is no need to write all the "missing" parameters, The following code looks much simpler:

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)
0xA3