Search here for all the info you want in this Blog

How to retrieve text from a Microsoft Word document

QuickTest Professional does not have special support for working with Microsoft Office applications. However, you can use the application's Automation Object Model.

You can refer to the Microsoft Word 2000 Visual Basic Reference for a complete listing of Word methods and properties that can be used within a QuickTest Professional (QTP) script. You can use these Word object methods within a QTP script to create documents, edit documents, spell check, etc.

For a complete listing of Word object's methods and properties, refer to MSDN Library - Microsoft Word Object Model.


Example:
' This example retrieves text from the specified Word document.
' Create the reference to the Word Automation Object.
Set wrdApp = CreateObject("Word.Application")
' Open the Word document.
Set wrdDoc = wrdApp.Documents.Open("C:\Temp\SampleWord.doc") 'replace the file with your MSDoc

With wrdDoc
    numPara = .Paragraphs.Count
    ' Retrieve the text in each paragraph of the document.
    For p = 1 To numPara
       startRange = .Paragraphs(p).Range.Start
       endRange = .Paragraphs(p).Range.End
       Set tRange = .Range(startRange, endRange)
       pstr = tRange.Text

       ' print out the string capture
       msgbox pstr
    Next
    ' Close the Word document.
    .Close ' close the document
End With

' Close the Word Application and release the object references.
wrdApp.Quit
Set wrdDoc = Nothing
Set wrdApp = Nothing

No comments:

Post a Comment