Consulting

Results 1 to 3 of 3

Thread: Using data from an Excel file that's embedded in Word

  1. #1

    Using data from an Excel file that's embedded in Word

    Hello all, I'm new to this thread.

    I have written VB code in an Excel file that successfully reads a Word file and stores each line and stores it in a cell.

    But I need to write something that can locate and read data, cell by cell, from any Excel files that are embedded in the Word doc and stores that data in the cells of the currently open Excel file.

    I searched through posts but couldn't find any relevant posts/replies.

    Thanks ahead for any help.

    FWIW, here's the code that successfully reads lines from the Word file and stores them in the cells of the currently open Excel file:

    Option Explicit
    Sub GetWordata()

    Dim singleLine As Paragraph
    Dim lineText As String
    Dim word_app As word.Application
    Dim wDoc As word.Document
    Dim r As Integer
    Dim i As Integer

    ' word_app.Application.Templates.LoadBuildingBlocks
    Set word_app = CreateObject("word.application")
    Set wDoc = word_app.Documents.Open("U:/ExcelApps/MergeExcelFiles/test/test.docx")
    word_app.Visible = True
    i = 1

    For Each singleLine In activeDocument.Paragraphs
    lineText = singleLine.Range.Text
    ' MsgBox lineText
    Sheets(1).Cells(1, i) = lineText
    ' Sheets("Data").Cells(1, i) = lineText
    i = i + 1
    Next singleLine
    wDoc.Close

    End Sub

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    For code to process embedded Excel workbooks in a document, see: https://social.msdn.microsoft.com/Fo...?forum=worddev. The code there is for converting such workbooks to Word tables, but the principles for data extraction are the same.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    Quote Originally Posted by macropod View Post
    For code to process embedded Excel workbooks in a document, see: https://social.msdn.microsoft.com/Fo...?forum=worddev. The code there is for converting such workbooks to Word tables, but the principles for data extraction are the same.
    Thanks. Looks promising. Will research code further.

Posting Permissions

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