none
Word Addin Error when calling the RRS feed

  • Question

  • I am writing a Word 2007 Add-On in VS 2008. I intercepted the File-> Save command so now instead of the SaveAs Dialog Box opening I open a custom form with a button. When I click the button and execute the following code I get an error message "Bad file name". 

    Dim

    objWordApp As New Word.Application

    objWordApp.Documents("c:\temp\newdoc.doc").SaveAs()

    thank you


    HD
    Friday, April 8, 2011 4:49 AM

Answers

  • Hi HD

    Going back to your original message I see:

     Dim objWordApp As New Word.Application

    The question is why you'd be doing this in an add-in? And add-in runs in-process with the application. When you execute the above line you're starting a new instance of the application. If you don't open a document in that instance, then there is no document to save. That explains the error you're seeing (and could be causing a lot of additional problems, further down the line).

    You need to reference the instance of the application in which your add-in is running. You should find examples of this in the documentation you're using to create your add-in. We could be able to help you with this if you could provide more information about what kind of add-in you're making. You've posted in the VSTO forum, but based on experience, this is no guarantee that you're actually using VSTO...


    Cindy Meister, VSTO/Word MVP
    Saturday, April 9, 2011 7:50 AM
    Moderator

All replies

  • Hi HD

    Is there a document actually open in Word that's been saved to this path? You're asking Word to work with a member of the Documents collection with that "name".

    I get the feeling you're wanting to save a document to that path. In that case, you need to use the parameters of the SaveAs method - you never use SaveAs without parameters. You only use Save() without parameters.

    objWordApp.Documents(1).SaveAs(FileName:="c:\tempate\newdoc.docx")

    And if you don't want to use the default file type (docx) you also need to specify the FileFormat parameter.


    Cindy Meister, VSTO/Word MVP
    Friday, April 8, 2011 7:15 AM
    Moderator
  • Hello Cindy

       Thanks you for your reply.

    When I run the command that you suggested I get the following error: "The requested member of the colletion does not exist" and when I run "objWordApp.Documents.Count" returns 0. This is strange because I get this error no matter if I open an existing document or a new document. I also tried this command  

    "objWordApp.ActiveDocument.SaveAs(FileName:=

    "c:\temp\newdoc.docx")"

    where I get error: "The command is not available because no document is open".

    thanks

     


    HD
    Friday, April 8, 2011 5:34 PM
  • Hi HD

    Going back to your original message I see:

     Dim objWordApp As New Word.Application

    The question is why you'd be doing this in an add-in? And add-in runs in-process with the application. When you execute the above line you're starting a new instance of the application. If you don't open a document in that instance, then there is no document to save. That explains the error you're seeing (and could be causing a lot of additional problems, further down the line).

    You need to reference the instance of the application in which your add-in is running. You should find examples of this in the documentation you're using to create your add-in. We could be able to help you with this if you could provide more information about what kind of add-in you're making. You've posted in the VSTO forum, but based on experience, this is no guarantee that you're actually using VSTO...


    Cindy Meister, VSTO/Word MVP
    Saturday, April 9, 2011 7:50 AM
    Moderator