VBA Word - Sélection texte entre deux mots

Bonjour la communtauté.

Etant novice, je me permets de faire appel à votre intelligence.

Je désespéremment depuis quelques jours, un code me permettant de sélectionner un texte entre deux mots dans un fichier word, pour pouvoir ensuite le copier dans un fichier excel.

Je vous joins le code fruit de mes recherches infructueuses.

Public Sub michel()

Dim fDialog As FileDialog, result As Integer
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)

'Optional: FileDialog properties
fDialog.AllowMultiSelect = False
fDialog.Title = "Select a file"
fDialog.InitialFileName = "C:\Users\Public\izi"
'Optional: Add filters
fDialog.Filters.Clear
fDialog.Filters.Add "Excel files", "*.xlsx"
fDialog.Filters.Add "All files", "*.*"

If fDialog.Show = -1 Then
   Debug.Print fDialog.SelectedItems(1)
End If

'CreateObject("Shell.application").Open (fDialog.SelectedItems(1))

Set wordapp = CreateObject("word.application")
wordapp.Documents.Open (fDialog.SelectedItems(1))
wordapp.Visible = True

Application.ScreenUpdating = False
wordapp.Selection.HomeKey Unit:=wdStory

    Do
        wordapp.Selection.Find.ClearFormatting
        With wordapp.Selection.Find
            .ClearFormatting
            .Text = "mot1*mot2"
            .Forward = True
            .Wrap = wdFindStop
            .MatchCase = True
            .MatchWildcards = True
            .Execute
        End With

    If wordapp.Selection.Find.Found Then
       texte = ActiveDocument.Range(Selection.Range.Start + 1, Selection.Range.End - 1)

            If InStr(Liste, texte) = 0 Then
                Liste = Liste & texte & vbCr
            End If
        End If
    Loop Until Not Selection.Find.Found

Workbooks("GX new.xlsm").Activate
Sheets("Feuil2").Activate
Range("A10").Value = Liste

End Sub

Bonjour John,

Ta macro VBA est-elle dans WORD ou bien EXCEL? En lisant ton code j'ai du mal de le déterminer.

Rechercher des sujets similaires à "vba word selection texte entre deux mots"