Dim objWordDoc ' Initaiate the Word Document object Set objWordDoc = CreateObject(“Word.Application”) ' New word document objWordDoc.Documents.Add ' Type some charecters in the newly created document objWordDoc.Selection.TypeText "My first Line" & vbnewline & "My Second Line" ' Save the document objWordDoc.ActiveDocument.SaveAs "C:\QTP\Docs\MyWordDoc.doc" ' Close word objWordDoc.Quit 'Release the object Set objWordDoc=Nothing
For more QTP example scripts click here
Helpful post for beginners like me... please keep posting such stuffs it will helps a lot... thanks :)
ReplyDeleteSure, will do that when I find time.
ReplyDeleteHey i'm getting error for this program.. Can you mention the details
ReplyDeleteIn which line You are Getting Error Plz Mention So We Can help you.
DeletePlease copy paste the error details.
ReplyDeleteInvalid character
ReplyDeleteLine (1): "Set objWordDoc = CreateObject(“Word.Application”)".
here within Create object use double inverted comma as in QTP script editor
DeleteYou have included the open inverted and close inverted comma's instead of "
ReplyDeletewatch the ones in your code.. it is not "
This gives error at save statement...
ReplyDeletei.e for below statement,
objWordDoc.ActiveDocument.SaveAs "C:\QTP\Docs\MyWordDoc.doc"
hay just give instead of that u r won path that stored in u r system ok c drive r d drive
Deletethis is good
ReplyDeleteWill same format work for remaining file types(excel or xml , ) ...pls help me
ReplyDeleteHow to create a excel or html file in qtp ...plz help me
ReplyDeleteSet objWordDoc = CreateObject(“excel.Application”)i'm getting a error if i write like this .
excellent!!
ReplyDeleteit works..
Hi guys,
ReplyDeleteI'm Having trouble saving the word doc. It gives me the following error. Pls help.
Word cannot save this file because it is already open elsewhere.
(C:\...\Desktop\UFT Screenshots.docx)
Line (144): "objWordDoc.ActiveDocument.SaveAs "C:\Documents and Settings\324025351\Desktop\UFT Screenshots"".
Super!!! It works! Thanks... Would greatly appreciate if you could provide the code to create Excel file with different column names (let's say "Links Name" and "URL"). Best regards,
ReplyDeletechage it as
ReplyDeleteSet objWordDoc = CreateObject("Word.Application")
Darshan Thakar