![]() |
| Le forum de référence en programmation et développement. Articles, cours et tutoriels du débutant au chef de projet et DBA confirmé. | |||||||
|
|||||||
![]() |
|
|
Outils de la discussion |
|
|
#1 (permalink) |
![]() Date d'inscription: février 2005
Localisation: Une petite rue qui "avait" un merle
Messages: 11 574
|
Objet : Comptabiliser les mots d'une liste dans un texte et connaître les N° de pages dans lesquelles ils se trouvent
Code :
Sub ChercherTrouver() Dim Recherche As Boolean Dim TabloMots As Variant, TabloPages(), TabloQu(), i As Integer Dim DerLigne As Byte TabloMots = Array("", "tata", "papa", "maman", "pépé", "mémé", "tonton", "michel") ReDim TabloPages(UBound(TabloMots)) ReDim TabloQu(UBound(TabloMots)) For i = 1 To UBound(TabloMots) Selection.HomeKey Unit:=wdStory With Selection.Find .Text = TabloMots(i) .MatchWholeWord = True 'recherche sur le mot entier (True par défaut) .Execute Recherche = .Found Do While Recherche TabloQu(i) = TabloQu(i) + 1 TabloPages(i) = TabloPages(i) & "," & Selection.Information(wdActiveEndPageNumber) .Execute Recherche = .Found Loop End With Next 'Affichage For i = 1 To UBound(TabloMots) If Not TabloQu(i) = Empty Then _ MsgBox TabloMots(i) & " a été trouvé " & TabloQu(i) & " fois " & _ " pages " & Right(TabloPages(i), Len(TabloPages(i)) - 1) Next End Sub Code :
.MatchWholeWord = False |
|
|
|
|
|
#2 (permalink) |
![]() Date d'inscription: février 2005
Localisation: Une petite rue qui "avait" un merle
Messages: 11 574
|
But : Permettre la saisie du mot ou de la liste des mots à chercher
Code :
Sub ChercherTrouver() Dim Recherche As Boolean, UnMot as string Dim TabloMots(), TabloPages(), TabloQu(), i As Integer Do UnMot = inputbox("Saisir un nouveau mot", "SAISIE de la LISTE","") if Trim(UnMot) <> "" then i = i + 1 Redim Preserve TabloMots(i) TabloMots(i) = UnMot endif Loop while trim(UnMot) <> "" if i = 0 then exit sub ReDim TabloPages(UBound(TabloMots)) ReDim TabloQu(UBound(TabloMots)) For i = 1 To UBound(TabloMots) Selection.HomeKey Unit:=wdStory With Selection.Find .Text = TabloMots(i) .MatchWholeWord = True 'recherche sur le mot entier (True par défaut) .Execute Recherche = .Found Do While Recherche TabloQu(i) = TabloQu(i) + 1 TabloPages(i) = TabloPages(i) & "," & Selection.Information(wdActiveEndPageNumber) .Execute Recherche = .Found Loop End With Next 'Affichage For i = 1 To UBound(TabloMots) If Not TabloQu(i) = Empty Then _ MsgBox TabloMots(i) & " a été trouvé " & TabloQu(i) & " fois " & _ " pages " & Right(TabloPages(i), Len(TabloPages(i)) - 1) Next End Sub
__________________
Je...ne...réponds...pas....aux...questions...techniques... par...mp La recherche (VBA-E) : Le Forum, La FAQ, Les cours et tutoriels, Contribuez, Les Sources et... l'Aide en ligne !!!
|
|
|
|
![]() |
![]() |
||
Compter le ou les mots d'une liste ds un document et donner leurs N° de pages
|
||
Offres d'
emploi informatique
sur Lesjeudis.com
|
| Outils de la discussion | |
|
|