ajit Posted August 19, 2018 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.au3Fetching info... test.docFetching info... Thanks for any help Ajit Edited August 19, 2018 by ajit
water Posted August 19, 2018 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: Reveal hidden contents UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
ajit Posted August 21, 2018 Author 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
water Posted August 23, 2018 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 Expand My UDFs and Tutorials: Reveal hidden contents UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
ajit Posted August 23, 2018 Author 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
water Posted August 23, 2018 Posted August 23, 2018 Glad you got it working My UDFs and Tutorials: Reveal hidden contents UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
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