Creating a MS Word Document using QTP 9.2

Creating a MS Word Document in QTP is not difficult but is very easy and one needs to know how to use the Word Application in QTP.

It is very easy to create a MS Word Document using QTP. There is no need to invoke the MS Word application in QTP but we require to use the Word Library by using the CreateObject method. If you have word on Excel Application in QTP then it is more or less similar working with Word Library. I will show a sample script to create a word document and also add some text to the word Document.


Script to create a Word Document in QTP

Set wordapp = CreateObject("Word.Application")
wordapp.visible = True
wordapp.documents.Add
wordapp.Selection.TypeText "This is a sample document"
wordapp.ActiveDocument.SaveAs "E:\testdoc.doc"
wordapp.Quit
Set wordapp = Nothing

We are using Wordapp.Visible = true because we want the application to be visible for the user while the text is being written to the Word Document. TypeText property is used to write the text in the word document. In order to save the document we use ActiveDocument menthod because in case if there are other word document already opened then the active document will be saved.

0 comments:

Post a Comment

/* Tynt Insight tracker ----------------------------------------------- */