Jump to content

Recommended Posts

Posted (edited)

Hi,

I am trying to color highlight text (any color other than yellow) in a word document.   Please can someone help me do it.  See the code below

 

$doc = (@ScriptDir & "\test.doc")

$str = "123"

$Fontcolor = 0xFF0000

;~ $Highlightcolor = "Bright Green)

$oWord = ObjCreate("Word.Application")
$oWord.Documents.Open($doc)
$oWord.selection.find.ClearFormatting() ; clear previous search

while $oWord.selection.find.execute($str) = True
$oWord.Selection.Expand
$oWord.selection.Font.Color = $Fontcolor
$oWord.selection.Font.Bold = True
$oWord.selection.Find.Forward = True
$oWord.Selection.Find.Execute
wend

$oWord.documents.Save
$oWord.Application.Quit
$oWord = 0
MsgBox(0, "Highlighter", "Finished")

Test Highlight.au3Fetching info... test.docFetching info...

Thanks for any help

Ajit

 

Edited by ajit
Posted

Did you have a look at the Word UDF that comes with AutoIt? IIRC _Word_DocRangeSet has an example in the help file that explains how to do. 

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

@Water

Thanks so much for your reply.

I am not sure if I am missing something but I cannot get the part on highlighting text.  Thanks for any help you can provide.

Regards,

Ajit

 

 

Posted

It is in the help file for _Word_DocRangeSet in section

  Quote
; Scene 2
; Move the end of the range one character to the left so the space to the next
; word isn't formatted and format the text bold, italic and underlined
Expand  

 

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

@water,

Thanks a lot.  The problem got solved.  Had earlier missed another post of yours on the topic which made things easy.  

 Regards,

Ajit

Posted

Glad you got it working :)

My UDFs and Tutorials:

  Reveal hidden contents

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...