UDF > Word >


_Word_DocFind

Ex�cute ou r�p�te l'op�ration de recherche sp�cifi�e

#include <Word.au3>
_Word_DocFind ( $oDoc [, $sFindText = "" [, $vSearchRange = 0 [, $oFindRange = Default [, $bForward = True [, $bMatchCase = False [, $bMatchWholeWord = False [, $bMatchWildcards = False [, $bMatchSoundsLike = False [, $bMatchAllWordForms = False [, $bFormat = False]]]]]]]]]] )

Param�tres

$oDoc Objet document Word
$sFindText [optionnel] Le texte � rechercher. Utilisez une cha�ne vide ("") pour rechercher seulement un format.
Vous pouvez rechercher des caract�res sp�ciaux en sp�cifiant les codes de caract�res appropri�s.
Par exemple,"^p" correspond � une marque de paragraphe et "^t" correspond � un caract�re de tabulation (par default = "")
$vSearchRange [optionnel] Sp�cifie la s�lection ou la plage dans laquelle effectuer la recherche. Peut �tre:
    -1 - Indique la s�lection actuelle
     0 - Indique le document complet (par d�faut)
Tout objet plage Word
$oFindRange [optionnel] Sp�cifie la plage retourn�e par le dernier appel � _Word_DocFind() .
Cela est n�cessaire si vous voulez rechercher l'occurrence suivante ou pr�c�dente de $sFindText.
Si d�fini � Default, la recherche d�bute au d�but de la $vSearchRange (valeur par d�faut)
$bForward [optionnel] True pour rechercher vers l'avant (vers la fin du document) (valeur par d�faut = True)
$bMatchCase [optionnel] Si True, la recherche est insensible � la casse (par d�faut = False)
$bMatchWholeWord [optionnel] Si True, recherche seulement des mots entiers (par d�faut = False)
$bMatchWildcards [optionnel] Si True, le texte recherch� contient des jokers (par d�faut = False )
$bMatchSoundsLike [optionnel] Si True, recherche des mots qui sonnent comme le texte de la recherche (par d�faut = False)
$bMatchAllWordForms [optionnel] Si True, recherche toutes les formes de la texte � recherche
(par exemple, "sit" trouve aussi "sitting" et "sat") (par d�faut = False)
$bFormat [optionnel] True pour que la recherche trouve le format en plus ou � la place du texte recherch� (par d�faut = False)

Valeur de retour

Succ�s: Retourne un objet plage pour le texte trouv�.
�chec: Retourne 0 et d�finit @error <> 0.
@error: 1 - $oDoc n'est pas un objet
2 - $vSearchRange n'est pas un objet
3 - $oFindRange n'est pas un objet
4 - $sFindText n'a pas �t� trouv�e

En relation

_Word_DocFindReplace

Exemple

Exemple 1

#include <MsgBoxConstants.au3>
#include <Word.au3>

; Cr�e un objet application
Local $oWord = _Word_Create()
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _
        "Error creating a new Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
; Ouvre un document test en lecture seule
Local $oDoc = _Word_DocOpen($oWord, @ScriptDir & "\Extras\Test.doc", Default, Default, True)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _
        "Error opening '.\Extras\Test.doc'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

;
; Cherche le dernier texte "test document" dans le document et le marque en gras.
;
Local $oRangeFound
#forceref $oRangeFound
$oRangeFound = _Word_DocFind($oDoc, "test document", 0, Default, False)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _
        "Error locating the specified text in the document." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
$oRangeFound.Bold = True
MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _
        "Last occurrence of string 'test document' in the document marked as bold.")

Exemple 2

#include <MsgBoxConstants.au3>
#include <Word.au3>

; Cr�e un objet application
Local $oWord = _Word_Create()
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _
        "Error creating a new Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
; Ouvre un document test en lecture seule
Local $oDoc = _Word_DocOpen($oWord, @ScriptDir & "\Extras\Test.doc", Default, Default, True)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _
        "Error opening '.\Extras\Test.doc'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

;
; Souligne le texte "line" des lignes 2-4.
;
Local $oRangeFound, $oSearchRange
$oSearchRange = _Word_DocRangeSet($oDoc, -1, $wdParagraph, 1, $wdParagraph, 3)
$oRangeFound = _Word_DocFind($oDoc, "line", $oSearchRange)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _
        "Error locating the specified text in the document." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
$oRangeFound.Underline = True
While 1
    $oRangeFound = _Word_DocFind($oDoc, "line", $oSearchRange, $oRangeFound)
    If @error Then ExitLoop
    $oRangeFound.Underline = True
WEnd
MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _
        "All occurrences of string 'line' in paragraphs 2-4 marked as underlined.")

Exemple 3

#include <MsgBoxConstants.au3>
#include <Word.au3>

; Cr�e un objet application
Local $oWord = _Word_Create()
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _
        "Error creating a new Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
; Ouvre un document test en lecture seule
Local $oDoc = _Word_DocOpen($oWord, @ScriptDir & "\Extras\Test.doc", Default, Default, True)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _
        "Error opening '.\Extras\Test.doc'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

;
; Cherche le texte "line" dans les lignes 2-4 et marque les nombres suivants en gras.
; Si le nombre est "3", ins�re le texte avant le texte "line".
;
Local $oRangeFound, $oSearchRange, $oRangeText
$oSearchRange = _Word_DocRangeSet($oDoc, -1, $wdParagraph, 1, $wdParagraph, 3)
$oRangeFound = _Word_DocFind($oDoc, "line", $oSearchRange)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _
        "Error locating the specified text in the document." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
; Marque le num�ro de ligne en gras. Cr�e une nouvelle plage d�plac�e d'un mot vers la droite
$oRangeText = _Word_DocRangeSet($oDoc, $oRangeFound, Default, 1, Default, 1)
$oRangeText.Bold = True
While 1
    $oRangeFound = _Word_DocFind($oDoc, "line", $oSearchRange, $oRangeFound)
    If @error Then ExitLoop
    ; Marque le num�ro de ligne en gras. Cr�e une nouvelle plage (dupliqu�e pour ne pas alt�rer le r�sultat de la recherche) et la d�place d'un mot vers la droite
    $oRangeText = $oRangeFound.Duplicate
    $oRangeText = _Word_DocRangeSet($oDoc, $oRangeText, Default, 1, Default, 1)
    $oRangeText.Bold = True
    ; Ins�re le texte si linenumber = 3
    If StringStripWS($oRangeText.Text, 8) = "3" Then $oRangeFound.InsertBefore("(maybe) ")
WEnd
MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _
        "All line numbers in paragraphs 2-4 marked as bold." & @CRLF & "Text inserted before 'line 3'.")

Exemple 4

#include <MsgBoxConstants.au3>
#include <Word.au3>

; Cr�e un objet application
Local $oWord = _Word_Create()
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _
        "Error creating a new Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
; Ouvre un document test en lecture seule
Local $oDoc = _Word_DocOpen($oWord, @ScriptDir & "\Extras\Test.doc", Default, Default, True)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _
        "Error opening '.\Extras\Test.doc'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

;
; Remplace le caract�re de contr�le 'paragraph' par paragraph + text + paragraph.
; Change seulement la premi�re occurrence.
;
Local $oRangeFound
$oRangeFound = _Word_DocFind($oDoc, "^p")
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _
        "Error locating paragraph control character in the document." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
$oRangeFound.InsertAfter("[New Line] ")
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _
        "Error inserting text after the paragraph control character in the document." & @CRLF & "@error = " & @error & _
        ", @extended = " & @extended)
MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", "Paragraph control character successfully replaced." & @CRLF & _
        "Text inserted in paragraph 2.")