Sub Concordance()


forme$ = InputBox$("Entrez le mot de votre choix", "Concordance")
choix$ = InputBox$("Tapez 1 pour lire vos résultats dans un fichier RTF ou"
+ Chr10 + " Tapez 2 pour les lire dans un fichier HTM", "Choix du format")

If choix$ = "1" Then

debut$ = "{\rtf1\ansi\ "
fin$ = "}"
grasdeb$ = "{\b "
grasfin$ = "}"
italdeb$ = "{\i "
italfin$ = "}"
souldeb$ = "{\ul "
soulfin$ = "}"
para$ = "{\par }"
Open "resu.rtf" For Output As 1

ElseIf choix$ = "2" Then

debut$ = "< HTML >< HEAD >< TITLE >< /TITLE >< /HEAD >"
fin$ = "< /BODY >< /HTML >"
grasdeb$ = "< b >"
grasfin$ = "< /b >"
italdeb$ = "< i >"
italfin$ = "< /i >"
souldeb$ = "< u >"
soulfin$ = "< /u >"
para$ = "< br >"
Open "resu.htm" For Output As 1

End If

Print #1, debut$ + para$
Open "duchn.txt" For Input As 2
comptforme = 0
comptligne = 0
While (EOF(2) = 0)

Line Input #2, ligne$
comptligne = comptligne + 1
k = InStr(ligne$, forme$)

If k > 0 Then
comptforme = comptforme + 1
gch$ = Left$(ligne$, 25)
lg = Len(forme$)
drt$ = Mid$(ligne$, k + lg, 25)
Print #1, souldeb$ + "Ligne n° " + Str$(comptligne) + " :" + soulfin$ + para$
Print #1, italdeb$ + gch$ + italfin$ + grasdeb$ + forme$ + grasfin$ + italdeb$ + drt$ + italfin$ + para$ + para$ + para$

End If Wend

Print #1, Str$(comptligne) + " lignes traitées" + para$
Print #1, Str$(comptforme) + " formes trouvées" + para$
Print #1, fin$
Close (1)
Close (2)

msg1$ = Str$(comptligne) + " lignes traitées"
msg2$ = Str$(comptforme) + " formes trouvées"
MsgBox (msg1$ + Chr(10) + msg2$)

If choix$ = "1" Then

Documents.Open FileName:="resu.rtf", ConfirmConversions:=False, ReadOnly:= _
False, AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:= _
"", Revert:=False, WritePasswordDocument:="", WritePasswordTemplate:="", _
Format:=wdOpenFormatAuto

ElseIf choix$ = "2" Then

Documents.Open FileName:="resu.htm", ConfirmConversions:=False, ReadOnly:= _
False, AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:= _
"", Revert:=False, WritePasswordDocument:="", WritePasswordTemplate:="", _
Format:=wdOpenFormatAuto

End If

End Sub