Results 1 to 7 of 7
  1. #1
    New Lounger
    Join Date
    Aug 2008
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    COM error on automation af WOrd (Office 2003 sp3,

    Hi, I'm working on an application there are opening a lot of .doc documents, reads them and close them again. It is done in a loop one doc at the time. Randomly there is an exception thrown with the text:

    A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in SortFields.exe
    Open doc fejl .. 127
    Serveren producerede en undtagelse. (Undtagelse fra HRESULT: 0x80010105 (RPC_E_SERVERFAULT))
    A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in SortFields.exe
    Objektet er frakoblet dets klienter. (Undtagelse fra HRESULT: 0x80010108 (RPC_E_DISCONNECTED))

    Sorry for the danish comments in the Exception text..
    As Google and I see this, it is the Word Com there are unavailable but how com this suddenly happens?
    Am I right at all in this assumption?
    K. R.
    Søren

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: COM error on automation af WOrd (Office 2003 sp3,

    Welcome to Woody's Lounge!

    Are you automating Word from an external application? If so, you must be very careful to fully qualify all references to Word objects.

    Let's say that you create a Word application object appWord.

    The following line is OK:

    MsgBox appWord.ActiveDocument.Name

    but the next one is disastrous:

    MsgBox ActiveDocument.Name

    Since ActiveDocument does not refer to appWord, it may become an orphan object that loses its connection to the Automation object.

  3. #3
    New Lounger
    Join Date
    Aug 2008
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: COM error on automation af WOrd (Office 2003 s

    Hi Hans .. thanks for the quick response ..
    Your observation seems to be the answer, but I'm still confused about how to implement it. My program does this:
    New wordApp
    loop:
    doc = wordApp.Documents.Open(bla..bla..)
    doc.ActiveWindow.Visible = false
    read the doc.tables in a foreach-loop
    doc.close()
    end loop.
    wordapp.quit()

    As I understand the doc is the same as what you call appWord.ActiveDocument.Name, so should I use that instead of refering to doc??

    K.R.
    Søren

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: COM error on automation af WOrd (Office 2003 s

    Your code looks OK, Using a variable doc this way is even better than using wordApp.ActiveDocument.

    ActiveDocument was only an example, I suggest that you look carefully through your code for possible problems of the same kind - using a Word object that doesn't refer back directly or indirectly to wordApp.

    If you wish you can post more of your code, in an attachment if it is more than, say, 30 lines.

  5. #5
    New Lounger
    Join Date
    Aug 2008
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: COM error on automation af WOrd (Office 2003 s

    The att. is my class .. It has come to my attention that it might be a problem that I call the constructer and then start the memberfunction "GetInfo()" in a seperate thread .. this is up for test .. Couldn't that give the situation where wordapp is in main thread and doc in worker thread, abd then looses control of the parent?
    /Søren
    Attached Files Attached Files

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: COM error on automation af WOrd (Office 2003 s

    I'm sorry, this is far outside my comfort range. I hope that someone else will be able to help you.

  7. #7
    New Lounger
    Join Date
    Aug 2008
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: COM error on automation af WOrd (Office 2003 s

    Thanks anyway Hans. Your answer gave the clue to get on with the problem....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •