Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Word text formatting
#1
Solved: 10 Years, 8 Months, 3 Weeks ago
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
Reply
#2
Solved: 10 Years, 8 Months, 3 Weeks ago
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

Reply
#3
Solved: 10 Years, 8 Months, 3 Weeks ago
Thanks
Saket Smile
Reply
#4
Solved: 10 Years, 8 Months, 3 Weeks ago
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
Reply
#5
Solved: 10 Years, 8 Months, 3 Weeks ago
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

Reply
#6
Solved: 10 Years, 8 Months, 3 Weeks ago
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Check the word and get no. of times that word in the webpage Sandeep.san229 0 1,176 10-31-2018, 06:42 PM
Last Post: Sandeep.san229
  pageDown in word.application wannel 0 1,666 11-25-2016, 10:06 PM
Last Post: wannel
  Automating Word Docs bart02 0 2,681 07-18-2014, 03:25 AM
Last Post: bart02
  Highlight the Found text in Word/notepad Sivakumar2186@gmail.com 2 3,469 10-21-2013, 06:31 PM
Last Post: BadrinarayananR
  Read text from text file and save it into a variable in qtp arpan 3 12,088 06-19-2013, 08:34 PM
Last Post: arpan

Forum Jump:


Users browsing this thread: 1 Guest(s)