; ======================================================================================= ; Title .........: Key Word in Context ; Description ...: Key Word in Context: the words of the index are shown with the surrounding text. ; Requirement(s).: Autoit v3.3.14.2 ; Author(s) .....: Giovanni Rossati (El Condor) ; Thanks to......: Water "Member's total reputation" of Autoit Forums ; Version........: 0.1.0 ; Date...........: 6 January 2016 ; ======================================================================================= #include #include #include Global Const $wdActiveEndPageNumber = 3 Global Const $wdActiveEndAdjustedPageNumber = 1 Local $oMyError = ObjEvent("AutoIt.Error", "ErrFunc") ; Install a custom error handler $oWord = _Word_Create() Global $sDocument = "C:\D\Condor\Documentazioni e Progetti\ContextIndexMS\cIndex.doc" $oDoc = _Word_DocOpen($oWord, $sDocument) ; Find first "_Heading 1" $oRangeFound = _Word_DocFind($oDoc, "CONTEXT", Default, Default, Default, Default, Default, Default, Default, Default, False) $hFl = FileOpen("c:\D\Condor\porko.txt",2) ; Find all selected style till end of document $ck = 0 $t = _Date_Time_GetTickCount() While 1 $ck = $ck + 1 $oRangeFound = _Word_DocFindEX($oDoc, "", 0, $oRangeFound, True, False, False, False, Default, Default, "Normale") If @error <> 0 Then ExitLoop If Mod($ck,10) = 0 Then ConsoleWrite(ceiling((_Date_Time_GetTickCount()- $t)/1000) & " " & $oRangeFound.Text & @LF) FileWriteLine($hFl, $oRangeFound.Information($wdActiveEndAdjustedPageNumber) & " " & $oRangeFound.style & " " & $oRangeFound.Text) if "A dialog is created by:" = StringLeft($oRangeFound.Text,23) then ExitLoop EndIf WEnd _Word_DocClose($oDoc) _Word_Quit($oWord) msgbox(0,"CuCu","See you later alligator") Func _Word_DocFindEX($oDoc, $sFindText, $vSearchRange, $oFindRange, $bForward, $bMatchCase, $bMatchWholeWord , $bMatchWildcards, $bMatchSoundsLike , $bMatchAllWordForms, $vFormat) Global $bFormat = False If Not IsObj($oDoc) Then Return SetError(1, 0, 0) If Not IsObj($oFindRange) Then Return SetError(3, 0, 0) $vSearchRange = $oDoc.Range() $oFindRange.Start = $oFindRange.End ; Search forward $oFindRange.End = $vSearchRange.End $oFindRange.Find.ClearFormatting() If $vFormat <> Default Then $bFormat = True $oFindRange.Find.Style = $vFormat EndIf $oFindRange.Find.Execute($sFindText, $bMatchCase, $bMatchWholeWord, $bMatchWildcards, $bMatchSoundsLike, _ $bMatchAllWordForms, $bForward, $WdFindStop, $bFormat) if "A dialog is created by:" = StringLeft($oRangeFound.Text,23) then return EndIf If @error Or Not $oFindRange.Find.Found Then Return SetError(4, 0, 0) Return $oFindRange EndFunc ;==>_Word_DocFind ; This is a custom error handler Func ErrFunc() $sHexNumber = Hex($oMyError.number, 8) MsgBox($MB_OK, "", "We intercepted a COM Error !" & @CRLF & _ "Number is: " & $sHexNumber & @CRLF & _ "WinDescription is: " & $oMyError.windescription) EndFunc ;==>ErrFunc