cancel
Showing results for 
Search instead for 
Did you mean: 

Error while creating word document using Sys.OleObject

SOLVED
ChandanD
Contributor

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()
}​

 

1 ACCEPTED SOLUTION

Accepted Solutions
hkim5
Staff

Re: Error while creating word document using Sys.OleObject

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. 

Best,
Justin Kim

View solution in original post

3 REPLIES 3
hkim5
Staff

Re: Error while creating word document using Sys.OleObject

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. 

Best,
Justin Kim

View solution in original post

ChandanD
Contributor

Re: Error while creating word document using Sys.OleObject

Will the same code be applicable for Excel?

Or there is some different method for excel. 

Tags (1)
hkim5
Staff

Re: Error while creating word document using Sys.OleObject

probably would be similar? 

Excel.Application

Excel.Application.Spreadsheet

so on and so forth?

The only difference would be that you might have to use nested for loops to target certain rows and columns when you are trying to populate the cells.

Best,
Justin Kim
New Here?
Join us and watch the welcome video:
Announcements