deanna
04-26-2010, 07:03 PM
My code opens and writes to a Word document. If another Word document is already open, a new instance of Word is created and I don't have any issues. Where I run into a problem is when processing my document. If another Word document is opened after I begin editing the first document, the second doc runs off the initial instance of Word and I lose my reference to the first doc with the error "The requested member of the collection does not exist".
Is there a way when I initiate Word for the document I am editing that I can lock that instance so that if Word is used to open any other documents while processing the subsequent documents will start up in a new instance of Word?
Or is there some way other than what I am doing for specifying the document I want to edit so that I don't lose reference to it when another document is opened during processing?
[CODE]
Public Class WordDoc
Private m_WordApp As Microsoft.Office.Interop.Word.ApplicationClass = Nothing
Private m_WordDoc As Document = Nothing
...
Public Sub OpenWordDocument(ByVal filename As String, ByVal OpenAsFormat As WdOpenFormat)
m_WordDoc = m_WordApp.Documents.Open(DirectCast(m_sWordDocFileName, Object), m_MISSINGVALUE, _...
...
Private Sub BuildWordDocument()
...
objWordDoc = New WordDoc()
objWordDoc.OpenWordDocument(sDocPath, WdOpenFormat.wdOpenFormatDocument)
...
[CODE]
Is there a way when I initiate Word for the document I am editing that I can lock that instance so that if Word is used to open any other documents while processing the subsequent documents will start up in a new instance of Word?
Or is there some way other than what I am doing for specifying the document I want to edit so that I don't lose reference to it when another document is opened during processing?
[CODE]
Public Class WordDoc
Private m_WordApp As Microsoft.Office.Interop.Word.ApplicationClass = Nothing
Private m_WordDoc As Document = Nothing
...
Public Sub OpenWordDocument(ByVal filename As String, ByVal OpenAsFormat As WdOpenFormat)
m_WordDoc = m_WordApp.Documents.Open(DirectCast(m_sWordDocFileName, Object), m_MISSINGVALUE, _...
...
Private Sub BuildWordDocument()
...
objWordDoc = New WordDoc()
objWordDoc.OpenWordDocument(sDocPath, WdOpenFormat.wdOpenFormatDocument)
...
[CODE]