Micro Focus QTP (UFT) Forums

Full Version: Word text formatting
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I need to read the text from the word document.
I am able to that... But now my requirement is to find the formatting of the searched text in word document.

e.g. Word document contains text "Test"

I need to find font type, Font size, Font name, Bold, Italic...etc of the text "Test" .

Thanks
Rahul
use selection object for this like SelectionObject.Font.Name

e.g
Code:
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Add()
Set objSelection = objWord.Selection
Print objSelection.Font.Name
Print objSelection.Font.Size
Thanks
Saket Smile
I am able search text in word document using 'Find & Replace functionality" but I want to select the searched text. So that I will able to find the formatting of that text only.
e.g. "This is Test" is the text available on the word document. I searched the text "Test" only and I only want to find the formatting of this word.

Please advice

Thanks
Rahul
if you are using Find and Replace method then when you do Find.Execute the Word Test will be selected there. you can retrieve the font info at that time
Saket,

I tried same but It is displaying the default fonts....
E.g. Word contains "this is Rahul" but following code dispplay the formatting of "this" not "Rahul"

Code:
Set oWord = CreateObject("Word.Application")
Set oDoc = oWord.Documents.Open("C:\test.docx")
searchString = "Rahul"
For p = 1 To oDoc.Paragraphs.Count
    startRange = oDoc.Paragraphs(p).Range.Start
    endRange = oDoc.Paragraphs(p).Range.End
    Set tRange = oDoc.Range(startRange, endRange)
    tRange.Find.Text = searchString
    tRange.Find.Execute
    If tRange.Find.Found Then
    msgbox "Word found in the document -->"& searchString     
    End If
    Dim oSelection  
    Set oSelection = oWord.Selection  
    msgbox oSelection.Font.Name
    msgbox oSelection.Font.Size
Next
oDoc.Close
oWord.Quit
Set oDoc = Nothing
Set oWord = Nothing