PoorLuzer Posted October 14, 2008 Posted October 14, 2008 People,I wanted to operate on highlighted text in a WORD (Office 2003) document.The operation needs to be conditional based on the type of highlighting present.For example, I want something like:1. If highlighting in yellow is present, delete text with that highlighting2. If highlighting in red is present, move such text to separate file OR remove formatting for now OR make font bold etcOverview of the logic will look like following:If Activedocument.Font.Shading.BackgroundPatternColor == wdColorYellowThen' This is commented text - delete this portion...Elseif Activedocument.Font.Shading.BackgroundPatternColor == wdColorRedThen' this needs to attract attention - move such text to seprate file OR remove formatting for now OR make font boldActivedocument.Font.Shading.BackgroundPatternColor = wdColorAutomatic....Note that the same document might have multiple highlighting in multiple colors.This solution is completely due to Ed Weber where he gave the complete code:http://www.productivitytalk.com/forums/ind...st&p=652416I have just modified his code in AutoIt v3 because that's what I am going to use.. adding and maintaining macros is too much of a chore for me.Run this code and bring your WORD doc into focus after dismissing the message box.expandcollapse popup#include <Word.au3> #cs Copyright 2008 PoorLuzer@gmail.com #ce const $wdFindStop = 0 const $wdAuto = 0 const $wdPink = 5 const $wdRed = 6 const $wdYellow = 7 const $wdGreen = 11 const $wdDarkRed = 13 const $wdDarkYellow = 14 const $wdGray50 = 15 const $wdGray25 = 16 MsgBox(0, "ALERT!", "After clicking OK on this message box, immediately bring the WORD window into focus!") Sleep(5000) $hWndWORD = WinGetHandle("[ACTIVE]", "") If 0 == $hWndWORD Then MsgBox(0, $msgBoxTitle, "WORD Failed!", 5) MsgBox(0, $msgBoxTitle, @ERROR) Exit EndIf $oWordApp = _WordAttach($hWndWORD, "HWND") If Not @error Then $oDoc = _WordDocGetCollection ($oWordApp, 0) If Not @error Then MsgBox(64, "Document FileName", $oDoc.FullName) Else MsgBox(64, "Failed", $oDoc.FullName) Exit EndIf EndIf $Rng = $oDoc.Range.Duplicate With $Rng.Find .ClearFormatting() .Format = True .Highlight = True .Wrap = $wdFindStop .Text = "" While $Rng.Find.Execute If $Rng.Find.Found Then If $wdRed == $Rng.HighlightColorIndex Then $Rng.HighlightColorIndex = $wdAuto $Rng.Bold = True EndIf EndIf $Rng.Start = $Rng.End + 1 $Rng.End = $oDoc.Range.End WEnd EndWith MsgBox(64, "Done", $oDoc.FullName)Highlight.au3
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