Error while creating word document using Sys.OleObject
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
(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()
}
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Justin Kim
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Will the same code be applicable for Excel?
Or there is some different method for excel.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Justin Kim
