View Single Post
 
Old 04-09-2023, 08:01 AM
syl3786 syl3786 is offline Windows 10 Office 2019
Advanced Beginner
 
Join Date: Jan 2023
Posts: 97
syl3786 is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
Change the main macro as follows and enter the names to search in the array.
Code:
Option Explicit

Private Const xlWB As String = "C:\Path\Empty Excel File name.xlsx"
Private Const xlSheet As String = "Sheet1"
Private vList() As Variant

Sub ExtractText()
    vList = Array("Speaker 1", "Speaker 2", "Speaker 3")
    Dim oDoc As Document
    Dim oRng As Range
    Dim i As Long

    Set oDoc = ActiveDocument
    Set oRng = oDoc.Range
    With oRng.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Font.Name = "Times New Roman"
        .Font.Bold = True
        Do While .Execute()
            For i = 0 To UBound(vList)
                If oRng.Text = CStr(vList(i)) Then
                     WriteToWorksheet xlWB, xlSheet, oRng.Text
                    Exit For
                 End If
            Next i
        Loop
    End With
lbl_Exit:
    Exit Sub
End Sub
It works very well! Words are not enough to express my gratitude.
Reply With Quote