Sub concordance()
' concordance Macro
' Macro créée le 20/05/2006 par JuLy
'
forme$ = InputBox$("entrez un mot", "concordance", "bougre")
choix$ = InputBox$("choisissez le format en tapant 1 pour rtf et 2 pour htm")
If choix$ = "1" Then
debut$ = "{\rtf1\ansi "
fin$ = "}"
grasdeb$ = "{\b "
grasfin$ = "}"
italdeb$ = "{\i "
italfin$ = "}"
souldeb$ = "{\ul "
soulfin$ = "}"
para$ = "{\par }"
Open "C:\resu.rtf" For Output As 1
Print #1, debut$ + para$
ElseIf choix$ = "2" Then
debut$ = "<HTML><HEAD><TITLE></TITLE></HEAD><BODY>"
fin$ = "</BODY></HTML>"
grasdeb$ = "<b>"
grasfin$ = "</b>"
italdeb$ = "<i>"
italfin$ = "</i>"
souldeb$ = "<u>"
soulfin$ = "</u>"
para$ = "<br>"
Open "C:\resu.htm" For Output As 1
Print #1, debut$ + para$
End If
Open "C:\duchn.txt" For Input As 2
comptligne = 0
comptforme = 0
While (EOF(2) = 0)
Line Input #2, ligne$
comptligne = comptligne + 1
k = InStr(ligne$, forme$)
If k > 0 Then
gch$ = Left$(ligne$, k - 1)
lg = Len(forme$)
drt$ = Mid$(ligne$, k + lg)
comptforme = comptforme + 1
Print #1, souldeb$ + "ligne n°" + Str$(comptligne) + ":" + soulfin$ + para$
Print #1, italdeb$ + gch$ + italfin$ + grasdeb$ + forme$ + grasfin$ + italdeb$ + drt$ + italfin$ + para$
End If
Wend
Print #1, Str$(comptligne) + " lignes traitées"
Print #1, para$ + Str$(comptforme) + " formes traitées"
Print #1, fin$
Close (1)
Close (2)
msg1$ = Str$(comptligne) + " lignes traitées"
msg2$ = Str$(comptforme) + " formes traitées"
MsgBox$ (msg1$ + Chr$(10) + msg2)
If choix$ = "1" Then
ChangeFileOpenDirectory _
"C:\Documents and
Settings\jU\Bureau\site LE CORRE JuLy\Résultats du programme
Concordance\"
Documents.Open FileName:="resu.rtf", ConfirmConversions:=False, ReadOnly:= _
False, AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:= _
"", Revert:=False, WritePasswordDocument:="", WritePasswordTemplate:="", _
Format:=wdOpenFormatAuto, DocumentDirection:=wdLeftToRight
ElseIf choix$ = "2" Then
ChangeFileOpenDirectory _
"C:\Documents and
Settings\jU\Bureau\site LE CORRE JuLy\Résultats du programme
Concordance\"
Documents.Open FileName:="resu.htm", ConfirmConversions:=False, ReadOnly:= _
False, AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:= _
"", Revert:=False, WritePasswordDocument:="", WritePasswordTemplate:="", _
Format:=wdOpenFormatAuto, DocumentDirection:=wdLeftToRight
End If
End Sub



Ce programme demande à l'utilisateur d'entrer un mot . Il ouvre
un fichier et recherche le mot demandé dans le texte contenu
dans le fichier. L'utilisateur a le choix entre deux formats : RTF ou
HTML pour le fichier résultat où apparaitront les
numéros des lignes dans lesquelles le mot demandé a
été trouvé. Un boite de dialogue apparait pour
annoncer à l'utilisateur combien de formes ont été
trouvées et combien de lignes ont été parcourures.
Enfin, le fichier s'ouvre automatiquement dans le format
demandé.