CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 2003
    Location
    Malaysia (P.J)
    Posts
    410

    Word automation problem

    I hve a problem... i get this error called "The server threw an exception"

    I installed my program in a client pc with the following code:

    Dim objWord2 As Object

    objWord2 = CreateObject("Word.Application")
    objWord2.Visible = True
    objWord2.Documents.Open(Environment.CurrentDirectory & "\abc.doc")
    'error occurs in the line below
    objWord2.ActiveDocument.SaveAs(FileName:="c:\mydoc\03020259-968.doc")

    It works in other pc except for one. That pc is running winxp sp2 n office xp.
    I reinstall office n still the same
    It there another code to save a document?

    Thanks in advance
    Back after a long hibernation.

  2. #2
    Join Date
    Feb 2005
    Location
    "The Capital"
    Posts
    5,306

    Thumbs up Re: Word automation problem

    Do you have the write access in that directory? If not then you won't be able to save a file. Also, make sure that the directory for "Save as" exists. Use proper exception handling techniques to get a proper error message. The error that you are getting does not reflect anything about the error..not meaningful at all. Also, make the line:
    Code:
    objWord2.ActiveDocument.SaveAs(FileName:="c:\mydoc\03020259-968.doc");
    as
    Code:
    objWord2.ActiveDocument.SaveAs(FileName:=@"c:\mydoc\03020259-968.doc")
    I am not sure if this works in VB.NET but that is how the paths are set in C# or else give one extra '/' at each location. Hope this helps.

  3. #3
    Join Date
    Jun 2003
    Location
    Malaysia (P.J)
    Posts
    410

    Re: Word automation problem

    Thanks for the reply... but it's still the same... n btw...
    objWord2.ActiveDocument.SaveAs(FileName:=@"c:\mydoc\03020259-968.doc");

    the "@" is only applied for C#... in vb we don't need this. I got another info over the web saying that it has something to do with norton...
    The way I c it... it has nothing to do with the code anymore.. it's just some external factor...

    Anymore ideas?
    Back after a long hibernation.

  4. #4
    Join Date
    Feb 2005
    Location
    "The Capital"
    Posts
    5,306

    Thumbs up Re: Word automation problem

    Quote Originally Posted by newvisva
    Thanks for the reply... but it's still the same... n btw...
    objWord2.ActiveDocument.SaveAs(FileName:=@"c:\mydoc\03020259-968.doc"); the "@" is only applied for C#... in vb we don't need this. I got another info over the web saying that it has something to do with norton...
    The way I c it... it has nothing to do with the code anymore.. it's just some external factor...Anymore ideas?
    Ok...Fine..(I worked with C# and hence was not sure about VB.Net) But did you try putting up proper exception handling routines? What's the exception that you are getting? By the way, yes the antivirus running on systems also sometimes causes issues..it might be accessing some directory/files or something and then when you code tries to do so... you get an exception that the file being read blah blah is being used by some other process/application...Try disabling the antivirus stuff on the machine for a moment and check if it works...

    Its hard to tell what might be causing this error without having to know the proper specific exception type that is being raised.

  5. #5
    Join Date
    Jun 2003
    Location
    Malaysia (P.J)
    Posts
    410

    Re: Word automation problem

    Exterminator, Thanks for the reply...

    I hv disable the realtime protection n still the same... I've also put an exception handler n still i get the same error msg. And then i found a few more pc with this prob... I think there must be other software inside it.

    Any other idea?
    Thanks
    Back after a long hibernation.

  6. #6
    Join Date
    Dec 2002
    Posts
    305

    Re: Word automation problem

    Instead of

    objWord2.Documents.Open(Environment.CurrentDirectory & "\abc.doc")
    'error occurs in the line below
    objWord2.ActiveDocument.SaveAs(FileName:="c:\mydoc\03020259-968.doc")

    try

    dim wdoc as Word.document=objWord2.Documents.Open(Environment.CurrentDirectory & "\abc.doc")
    wdoc.saveas(FileName:="c:\mydoc\03020259-968.doc")

    It may be that the active document gets redefined in the server as different users access Word in the server - just a guess. Let me know if it helps.

  7. #7
    Join Date
    Dec 2002
    Posts
    305

    Re: Word automation problem

    Another thing you may try is instead of opening a server document and then saving it to the PC within Word, copy the document from server to PC first using 'File.Copy' from 'Systems.IO', and then open it in Word. Good luck.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured