Results 1 to 2 of 2

Thread: Need help about Copy Text from Word To Excel

  1. #1

    Question Need help about Copy Text from Word To Excel

    Hi everyone,

    I have a VBA code that currently allows me to copy the selected text from Word to a designated Excel file. However, I'm struggling to modify the code to copy specific text from Word to Excel instead. I'm not sure how to write the code to achieve this.

    Here's the code I have so far:

    Sub CopyTextToExcel()
        Dim objExcel As Object
        Dim objWorkbook As Object
        Dim objWorksheet As Object
        Dim strText As String
        Dim rngDestination As Object
        ' Create a new Excel application
        Set objExcel = CreateObject("Excel.Application")
        ' Open an existing workbook or create a new one
        Set objWorkbook = objExcel.Workbooks.Open("C:\Users\Desktop\Template.xlsx") ' Replace with the actual path
        ' Set the destination worksheet
        Set objWorksheet = objWorkbook.Worksheets("LIST") ' Replace with the actual sheet name
        ' Set the destination range
        Set rngDestination = objWorksheet.Range("A2") ' Replace with the actual cell range
        ' Get the specific text from Word
        strText = ActiveDocument.Range.Text
        ' Copy the text to Excel
        rngDestination.value = strText
        ' Save and close the workbook
        ' Quit Excel
        ' Clean up the objects
        Set rngDestination = Nothing
        Set objWorksheet = Nothing
        Set objWorkbook = Nothing
        Set objExcel = Nothing
        End With
    End Sub
    I would like to modify the code to copy specific text from Word to Excel based on certain criteria. For example, Font.Name = "Times New Roman", Font.Size = 14, Font.Bold = True.

    Could someone please guide me on how to modify the code to achieve this? Any help or suggestions would be greatly appreciated.

    Thank you in advance for your assistance!

  2. #2
    You can use the Font property of Selection object to check the font name, size, and if it is bold. Selection.Font property (Word) | Microsoft Learn

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts