Forum Discussion

ChandanD's avatar
ChandanD
Contributor
6 years ago
Solved

Error while creating word document using Sys.OleObject

Hello,

 

I am unable to create a word document and open the word document. I am adding error message of 

Sorry, we couldn't find your file. Was it moved, renamed, or deleted?
 (C:\KBData\...\Win10\Word_test.docx)

This is the code which I am using.

 

function worddoc ()
{
  Word = Sys.OleObject("Word.Application")
  Word.Visible = true
  Word.Documents.Open("C:\\KBData\\Training_svn\\trunk\\Win10\\Word_test.docx")
  Word.Documents.Add()
//  oWord.Documents.Close()
//  oWord.Quit()
}​

 

  • def Word_test():
      Word = Sys.OleObject["Word.Application"]
      Log.Message("Opening Word and making it visible")
      Word.Visible = True
      #Opening up a new doc
      Word.Documents.Add()
      #activated doc and adding some text
      Word.ActiveDocument.Content = "Here is some text"
      #saving as a new file
      Word.ActiveDocument.SaveAs("C:\\Users\\justin.kim\\OneDrive - SmartBear Software, Inc\\Word_TC_test.docx")
      Log.Message("Shutting MS Word down")
      Word.Quit()

     

    So the error message you are getting is telling me that you have not yet created a word doc with that name. 

    If you are choosing to create a file, then you must save that file first. Although the (Python) syntax above is different, the order in which I used the methods are the same.