Micro Focus QTP (UFT) Forums
Word Doc Automation - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Word Doc Automation (/Thread-Word-Doc-Automation)



Word Doc Automation - susangeet004 - 01-12-2011

Hello All,

I was going thorugh the MS Word automation article by Saket in this site.


I tried running the code below twice

Code:
Dim oWord  Set oWord = CreateObject("Word.Application")
     oWord.Documents.Add  
     oWord.Selection.TypeText "Hello World!!!"
     oWord.ActiveDocument.SaveAs "c:\test.doc"
     oWord.Quit
     Set oWord = Nothing

For the first run it saved the file as test.doc under C drive with Hello World!!! written inside it.

During the second run insted of "Hello World", I put "My India" and the content was overwritten.

Now my question is, we have used "SavedAs" method to save a file in both run. For the 1st run the file gets created but for the 2nd run it should have thrown error for we are trying to save
another file having same name under the same directory. But it didn't. It just overwrote the file. So here "SaveAs" method worked as "Save" method.

Does "SaveAs" method implicitly says to overwrite an existing file?? If no what is the reason here??


Thanks!!!!