ajit Posted August 19, 2018 Share Posted August 19, 2018 (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.au3test.doc Thanks for any help Ajit Edited August 19, 2018 by ajit Link to comment Share on other sites More sharing options...
water Posted August 19, 2018 Share Posted August 19, 2018 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: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
ajit Posted August 21, 2018 Author Share Posted August 21, 2018 @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 Link to comment Share on other sites More sharing options...
water Posted August 23, 2018 Share Posted August 23, 2018 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 My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
ajit Posted August 23, 2018 Author Share Posted August 23, 2018 @water, Thanks a lot. The problem got solved. Had earlier missed another post of yours on the topic which made things easy. Regards, Ajit Link to comment Share on other sites More sharing options...
water Posted August 23, 2018 Share Posted August 23, 2018 Glad you got it working My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now