locked
run-time error '-2147417851 (80010105)' RRS feed

  • Question

  •  

    I have an MS Access file that opens a word template, populates it with data and saves it to a local share. The following code produces the above error:

     

    Dim WordObj As Word.Application
        
      Set WordObj = CreateObject("Word.Application")
      WordObj.Visible = True
      WordObj.Activate
      WordObj.ShowMe
      WordObj.WindowState = wdWindowStateMaximize
      WordObj.Documents.Add(GetTemplatePath(strDocPath))
    
    WordObj.ActiveDocument.SaveAs FileName:=FullDocName, FileFormat:=12 //this line produces the above error

    I have tried many combinations of early / late binding with the word application object and always get the same result. The word document will open and the functions which insert text will run successfully, but the document will not be saved and if any further editing is attempted Word will crash.

    I suspect that code isnt the problem; I have another identical workstation that is able to open and save the output document. What external factors could cause this?

    Saturday, February 19, 2011 11:12 PM

Answers

  • What version of office do you have installed on your PC?

    You can specify the version of excel you are creating the object.

    From :

    Set WordObj = CreateObject("Word.Application")

    to :

    Set WordObj = CreateObject("Word.Application.12")

     

    You also may want to try using the following

    WordObj.ActiveDocument.SaveAs FileName:=FullDocName, FileFormat:=acFileFormatAccess2007

     

    Check the menu in access vba Tools - References Microsoft Word XX.X object Library.  You may have to browse for a newer version of the object library.  what sometimes hapPens if the macro was developed on a PC with 2003 the reference may be pointing to the object library 11.0 while you need 12.0.

    Make sure the version  of the object library is compatible with Word 2007.  Version 12 is office 2007.  The create object will automatically use the defualt version of office that is installed on your PC.  If you have  office 2010 installed you may need to specify a differnt version.

    Errors like -2147417851 (80010105) are usually caused by not having the priveledge to open the file.  Make sure you can open the file by double clicking on the file and opening.  I would aslo suspect you would get the error if your configuration (like the reference) doesn't support office 2007.

     

     


    jdweng
    • Marked as answer by Bruce Song Friday, February 25, 2011 9:50 AM
    Sunday, February 20, 2011 12:13 AM
  • Wrong approach. You mix the application object with document object. Try this:

     

      Dim appWord As New Word.Application
      Dim objWord As Word.Document


      Set objWord = appWord.Documents.Add(GetTemplatePath(strDocPath))

      appWord.visible = True
      appWord.Activate
      appWord.ShowMe
      appWord.WindowState = wdWindowStateMaximize

      appWord.ActiveDocument.SaveAs FileName:=FullDocName, FileFormat:=12

    Greg

    • Marked as answer by Bruce Song Friday, February 25, 2011 9:50 AM
    Sunday, February 20, 2011 8:25 PM
  • Hi Richard,

    it's interesting because this cide works fine for me with Office 2007:

     

     Set wordobj = CreateObject("Word.Application")
     wordobj.Visible = True
     wordobj.Activate
     wordobj.ShowMe
     wordobj.WindowState = wdWindowStateMaximize
     wordobj.Documents.Add "********\Desktop\test.docx"
     wordobj.ActiveDocument.SaveAs FileName:="********\Desktop\test1", FileFormat:=12
     wordobj.Quit
     Set wordobj = Nothing
    

     

    But I've been facinf the situation when Excel automation hadn't worked until setting the whole object "stairway".

    Suggestions:

    - Are you sure that exactly the last line causes an error?

    - Does FullDocName have an extension part?

    - Do you have more than one version of Office installed on this workstation?


    Andrey V Artemyev | Saint-Petersburg, Russia
    • Marked as answer by Bruce Song Friday, February 25, 2011 9:50 AM
    Sunday, February 20, 2011 9:25 PM

All replies

  • What version of office do you have installed on your PC?

    You can specify the version of excel you are creating the object.

    From :

    Set WordObj = CreateObject("Word.Application")

    to :

    Set WordObj = CreateObject("Word.Application.12")

     

    You also may want to try using the following

    WordObj.ActiveDocument.SaveAs FileName:=FullDocName, FileFormat:=acFileFormatAccess2007

     

    Check the menu in access vba Tools - References Microsoft Word XX.X object Library.  You may have to browse for a newer version of the object library.  what sometimes hapPens if the macro was developed on a PC with 2003 the reference may be pointing to the object library 11.0 while you need 12.0.

    Make sure the version  of the object library is compatible with Word 2007.  Version 12 is office 2007.  The create object will automatically use the defualt version of office that is installed on your PC.  If you have  office 2010 installed you may need to specify a differnt version.

    Errors like -2147417851 (80010105) are usually caused by not having the priveledge to open the file.  Make sure you can open the file by double clicking on the file and opening.  I would aslo suspect you would get the error if your configuration (like the reference) doesn't support office 2007.

     

     


    jdweng
    • Marked as answer by Bruce Song Friday, February 25, 2011 9:50 AM
    Sunday, February 20, 2011 12:13 AM
  • Wrong approach. You mix the application object with document object. Try this:

     

      Dim appWord As New Word.Application
      Dim objWord As Word.Document


      Set objWord = appWord.Documents.Add(GetTemplatePath(strDocPath))

      appWord.visible = True
      appWord.Activate
      appWord.ShowMe
      appWord.WindowState = wdWindowStateMaximize

      appWord.ActiveDocument.SaveAs FileName:=FullDocName, FileFormat:=12

    Greg

    • Marked as answer by Bruce Song Friday, February 25, 2011 9:50 AM
    Sunday, February 20, 2011 8:25 PM
  • Hi Richard,

    it's interesting because this cide works fine for me with Office 2007:

     

     Set wordobj = CreateObject("Word.Application")
     wordobj.Visible = True
     wordobj.Activate
     wordobj.ShowMe
     wordobj.WindowState = wdWindowStateMaximize
     wordobj.Documents.Add "********\Desktop\test.docx"
     wordobj.ActiveDocument.SaveAs FileName:="********\Desktop\test1", FileFormat:=12
     wordobj.Quit
     Set wordobj = Nothing
    

     

    But I've been facinf the situation when Excel automation hadn't worked until setting the whole object "stairway".

    Suggestions:

    - Are you sure that exactly the last line causes an error?

    - Does FullDocName have an extension part?

    - Do you have more than one version of Office installed on this workstation?


    Andrey V Artemyev | Saint-Petersburg, Russia
    • Marked as answer by Bruce Song Friday, February 25, 2011 9:50 AM
    Sunday, February 20, 2011 9:25 PM