Micro Focus QTP (UFT) Forums
Word text formatting - 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: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: Word text formatting (/Thread-Word-text-formatting)



Word text formatting - Rahull - 01-04-2011

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



RE: Word text formatting - Saket - 01-04-2011

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



RE: Word text formatting - Rahull - 01-04-2011

Thanks
Saket Smile



RE: Word text formatting - Rahull - 01-05-2011

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



RE: Word text formatting - Saket - 01-05-2011

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


RE: Word text formatting - Rahull - 01-05-2011

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