Using Interop.Word for Synonyms

Hi All,

I have developed an application that uses MS Word to check for sysnonyms of a word. It all works fine on my local machine(win xp pro sp2). However when I ran the application on our live server(win2k) I get this error:

System.Runtime.InteropServices.COMException: Command failed

I have Office installed  on both machines.

When I check the Task Manager on the remote machine, I can see that an instance of winword.exe started.

===========code======================
Private Sub SpellCheck(ByVal text As String)
        Dim arrWords() As String
        Dim HTML As String
        Dim strSynonyms As String
        'Dim wrdDoc As Object = New Word.ApplicationClass
        Dim arrHTML As ArrayList = New ArrayList
        Dim strWord As String
        Dim wrdDoc As New Word.Application
        Dim SpellingSuggestions As Word.SpellingSuggestions
        Dim SpellingSuggestion As Word.SpellingSuggestion
        Dim Synonyms As Word.SynonymInfo

        wrdDoc.Documents.Add()
        Try

            arrWords = text.Split("/")
               For Each strWord In arrWords
                Synonyms = wrdDoc.SynonymInfo(Trim(strWord))
                If Synonyms.MeaningCount > 0 Then
                    HTML = "<table width=800  border=0 cellspacing=0 cellpadding=0><tr>" & _
                            "<td width=200 align=left valign=middle class=pagebody>" & strWord & "</td><td width=600  align=left valign=middle class=pagebody>"

                    For Each strSynonyms In Synonyms.MeaningList
                        HTML = HTML & "<input type=checkbox id=synonym name=synonym value=""" & strSynonyms & """>" & strSynonyms & "&nbsp;&nbsp;"
                    Next
                    HTML = HTML & "</td></tr><tr><td colspan=2 align=left valign=top><hr></td></tr></table>"
                End If
                If HTML <> Nothing Then
                    arrHTML.Add(HTML)
                    HTML = ""
                End If

            Next

            wrdDoc.Documents.Close()
            wrdDoc.Quit()
            With dlSynonyms
                .DataSource = arrHTML
                .DataBind()
            End With

        Catch ex As Exception
            wrdDoc.Documents.Close()
            wrdDoc.Quit()
            With lblError
                .Text = "Spell Check Function : " & ex.Message & ex.InnerException.ToString
                .Visible = True
            End With
        End Try

    End Sub
===============================================================

And I am using Imports System.Runtime.InteropServices

Any help would be much appreciated.

Thanks
Andrew
midasmanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mcdown75Commented:
Your machine is trying to access the command on the server.  You either need to install the .dll that performs this function on the server, or direct your program to access the .dll from the local machine, instead of the network.

0
midasmanAuthor Commented:
Thanks mcdown75 but I do have MS Office on the remote machine as well.

Could it be a problem setting the reference properties of the Interop.Word ?

BTW I am now exploring trying to use Office PIAS.


0
midasmanAuthor Commented:
OK tried the Office PIAs as well and getting the same error. Have to say that this is fustrating!
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

midasmanAuthor Commented:
Increasing pionts to 400  for this one.
0
mcdown75Commented:
My apologies.  This is a bug, but I have a link to an article that explains the resolution.  Try this:

http://www.dotnet247.com/247reference/a.aspx?u=http://www.kbalertz.com/Feedback_815633.aspx

Hope that helps.
0
midasmanAuthor Commented:
Thanks for that. But how do i apply it to my code?

This is what MS says:
==================
Dim obj As Object
    obj = New Project1.Class1()
    Dim inval As Object
    'Marshal the object before passing it to the method.
    inVal = New System.Runtime.InteropServices.DispatchWrapper(Nothing)
    obj.MyFunc(inval)
========================

Thanks once again.
0
mcdown75Commented:
I think what you want to do is this

Dim strWord as Object
strWord = new.system.runtime.interopservices.dispatchwrapper(nothing)
Synonyms = wrdDoc.SynonymInfo(Trim(strWord))

I may be wrong, but according to the article that's what it looks like.

Does your debug statement give any clue as to the exact line that the code is dying on?  If the above doesn't work, the line it dies on would be very helpful in figuring out what call is going haywire.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
midasmanAuthor Commented:
Thank you mcdown75 for all your help. I have managed to get it working now on the remote server.

However another problem has come up which is the app is now not releasing the instance of Word that is creates. On my local machine no problem but on the remote machine just wont close out the instance. Bloody headache this turned out to be!

Anyway if you have any thoughts that would be great. I am awarding you the points anyway.

Thank you very much!

Andrew
0
mcdown75Commented:
Have you tried this?

strWord = nothing
strWord.close

That is the only thing I can see in your code that might be hanging open.  You close your data connections, but it has to be something like that which is hanging open.  At the end, start typing your variables and anything that has a .close option, do it.  See if that works.  

Do you have anything like a quick watch window that will show you what is still hanging out there?
0
midasmanAuthor Commented:
yeah i have tried all that and more..

wrdDoc.Quit(false,nothing,nothing)
System.Runtime.InteropServices.Marshal.ReleaseComObject(wrdDoc)
wrdDoc = Nothing

Absolutely no go. This has forced me now into trying to use an existing instance of word if it exists before creating a new one. Still working on it.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.