6 Replies Latest reply on May 12, 2015 2:15 PM by David Hinners

    Why would I get a Run-time error '462':

    David Hinners

      The sub-text in the error dialogue says:

      The remote server machine does not exist or is unavailable

       

      I am trying to use the Microsoft Word spell-check engine to check the spelling in a user-entry field on a user form in a VBA macro.  It works fine as long as I manually launch Word before running my macro, but it then proceeds to launch a second Word window to do the operation anyway.

       

      The portion of the code where it fails is very simple:

       

      Public swApp As Object

      Public mwApp As Object

       

      Sub main()

       

      Set swApp = Application.SldWorks

      Set mwApp = Word.Application

       

      UserForm1.Show

      End Sub

       

      When it fails, it stops on the line to create the mwApp object.  In other words, it never gets to the UserForm1 code.

       

      Any ideas?

        • Re: Why would I get a Run-time error '462':
          Ivana Kolin

          for MS Office I always use this code

           

          Dim mwApp as Word.Application
            On Error Resume Next
          
            ' Get existing instance of Word if it exists.
            Set mwApp = GetObject(, "Word.Application")
          
            If Err <> 0 then
            ' If GetObject fails, then use CreateObject instead.
            Set mwApp = CreateObject("Word.Application")
            End If
          
            • Re: Why would I get a Run-time error '462':
              David Hinners

              You are right, Ivana, that I could improve my code to create the application object quite a bit.  However, after some more research, it looks like my main problem is occurring where I close the application object and destroy it.  The problem only shows up the second time I run my code though, so the point at which it fails was a bit deceptive.  I did not post the section that is actually causing the problem which appears to be that in the task manager, there is an orphaned process that remains running after my macro completes.  I will post a further update once I incorporate some of the ideas from you and Keith.

            • Re: Why would I get a Run-time error '462':
              Keith Rice

              Hopefully Ivana's answer will help you, but if not I would highly recommend you use StackOverflow.com for non-SolidWorks API questions. I have searched for this message for you on SO here.

               

              Keith

              SolidWorks API Training

              • Re: Why would I get a Run-time error '462':
                David Hinners

                I found some further information that seems to tie in with input from Ivana and Keith above.  This is from:

                 

                https://support.microsoft.com/en-us/kb/189618/

                 

                It reads in part: "Visual Basic has established a reference to Word due to a line of code that calls a Word object, method, or property without qualifying it with a Word object variable. Visual Basic does not release this reference until you end the program. This errant reference interferes with automation code when the code is run more than once."

                 

                There is also some example code illustrating the issue.  I will post another update once I get a chance to study it.