Public Sub SelPara(Titre As String) Selection.HomeKey Unit:=wdStory Dim txte As String Dim still As String Dim klk As String Dim klk2 As String Dim titretrouve As Boolean titretrouve = True With Selection.Find .Forward = True .ClearFormatting .MatchWholeWord = False .MatchCase = False .Wrap = wdFindContinue .Text = Titre Do .Execute If .Found = True Then 'si on a trouvé quelque chose 'Pour eviter de selectionner le titre du sommaire If Selection.InRange(ActiveDocument.TablesOfContents(1).Range) = False Then still = Selection.Paragraphs.Last.Style klk = Left(still, 5) If klk = "Titre" Then Selection.GoToNext what:=wdGoToLine 'pour ne pas selectionner le titre Debug.Print Selection.MoveDown(Unit:=wdParagraph, Count:=2, Extend:=wdExtend) Exit Do 'on à trouvé ce que l'on cherchait donc on sort End If End If Else titretrouve = False ' MsgBox "vérifier le titre " Exit Do 'on à pas trouvé ce que l'on cherchait alors on sort End If DoEvents Loop If titretrouve Then 'pour eviter une boucle infinie Do still2 = Selection.Paragraphs.Last.Style klk2 = Left(still2, 5) If klk2 = "Titre" Then Debug.Print "titre suivant trouvé" Debug.Print Selection.MoveUp(Unit:=wdParagraph, Count:=1, Extend:=wdExtend) 'pour ne pas sélectionner le titre suivan Exit Do Else Debug.Print Selection.MoveDown(Unit:=wdParagraph, Count:=1, Extend:=wdExtend) End If DoEvents Loop While klk2 <> "Titre" End If End With Debug.Print Selection.Text txte = RetourChariot(Selection.Text) Me.Textpara.Text = txte End Sub
Quelques mots de remerciements seront grandement appréciés. Ajouter un commentaire
116 internautes nous ont dit merci ce mois-ci
Sub test() Dim Titre As String Titre = "mon titre" With Selection.Find .Forward = True .ClearFormatting .MatchWholeWord = False .MatchCase = False .Wrap = wdFindContinue .Text = Titre Do .Execute If .Found = True Then 'si on a trouvé quelque chose 'Pour eviter de selectionner le titre du sommaire If Selection.InRange(ActiveDocument.TablesOfContents(1).Range) = False Then With .Parentraph 'on etend la selection au paragraphe .Expand Unit:=wdParagraph .Copy Exit Do 'on à trouvé ce que l'on cherchait donc on sort End With End If Else Exit Do 'on à pas trouvé ce que l'on cherchait alors on sort End If DoEvents Loop End With End Sub
Public Sub test()
Dim Titre As String
Titre = "Actualisation du document et de ses annexes"
With Selection.Find
.Forward = True
.ClearFormatting
.MatchWholeWord = False
.MatchCase = False
.Wrap = wdFindContinue
.Text = Titre
Do
.Execute
If .Found = True Then 'si on a trouvé quelque chose
'Pour eviter de selectionner le titre du sommaire
If Selection.InRange(ActiveDocument.TablesOfContents(1).Range) = False Then
With .Parentraph
'on etend la selection au paragraphe
.Expand Unit:=wdParagraph
.Copy
Exit Do 'on à trouvé ce que l'on cherchait donc on sort
End With
End If
Else
Exit Do 'on à pas trouvé ce que l'on cherchait alors on sort
End If
DoEvents
Loop
End With
End Sub
Sub test() Dim Titre As String Titre = "mon titre" With Selection.Find .Forward = True .ClearFormatting .MatchWholeWord = False .MatchCase = False .Wrap = wdFindContinue .Text = Titre Do .Execute If .Found = True Then 'si on a trouvé quelque chose 'Pour eviter de selectionner le titre du sommaire If Selection.InRange(ActiveDocument.TablesOfContents(1).Range) = False Then With .Parent 'on etend la selection au paragraphe .Expand Unit:=wdParagraph .Copy Exit Do 'on à trouvé ce que l'on cherchait donc on sort End With End If Else Exit Do 'on à pas trouvé ce que l'on cherchait alors on sort End If DoEvents Loop End With End Sub
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.