+ Reply to Thread
Results 1 to 2 of 2

Get Word Tables from Multiple Documents into Excel

  1. #1
    Registered User
    Join Date
    11-07-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    3

    Get Word Tables from Multiple Documents into Excel

    Hello all...

    I know, you'll curse my stupidity, but I know you lot are supreme when it comes to VBA challenges. I'm sure this one is easy for you, not for me unfortunately.

    Running Office 2013 - I have a varying number of Word 2013 documents containing tables (i may need to choose the particular table number which should be the same across each document) in a specific folder. I need to extract the contents of each table into a single Excel Workbook/sheet. I know this is possible as I have found the code (there I go again!) to carry out that task for a single Word document.

    My question therefore, based on the code below, is how do I adjust this such that each document in the specified folder is opened, and table data copied (etc)?

    Does anyone feel up to helping? A beer has your name on it if you can successfully help me! (you only need to help with this, the rest of my problems, well, they're for me to deal with)

    Here's the Code: (and thanks to www.exceltrainingvideos.com for this)

    Sub importTableDataWord()
    Dim WdApp As Object, wddoc As Object
    Dim strDocName As String
    On Error Resume Next
    Set WdApp = GetObject(, "Word.Application")
    If Err.Number = 429 Then
    Err.Clear
    Set WdApp = CreateObject("Word.Application")
    End If
    WdApp.Visible = True

    strDocName = "c:\users\jobloggs\desktop\appraisal\Worddocument.docx"

    WdApp.Activate

    Set wddoc = WdApp.Documents(strDocName)

    If wddoc Is Nothing Then Set wddoc = WdApp.Documents.Open(strDocName)
    wddoc.Activate
    Dim Tble As Integer
    Dim rowWd As Long
    Dim colWd As Integer
    Dim x As Long, y As Long
    x = 1
    y = 1
    With wddoc
    Tble = wddoc.tables.Count
    If Tble = 0 Then

    MsgBox "No Tables found in the Word document", vbExclamation, "No Tables to Import"
    Exit Sub
    End If


    'For i = 1 To Tble
    i = 3
    With .tables(i)
    For rowWd = 1 To .Rows.Count
    For colWd = 1 To .Columns.Count
    Cells(x, y) = WorksheetFunction.Clean(.cell(rowWd, colWd).Range.Text)

    y = y + 1

    Next colWd
    y = 1
    x = x + 1

    Next rowWd
    End With

    'Next
    End With



    wddoc.Close Savechanges:=False

    WdApp.Quit


    Set wddoc = Nothing
    Set WdApp = Nothing


    End Sub

  2. #2
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Get Word Tables from Multiple Documents into Excel

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here
    Click the * Add Reputation button in the lower left hand corner of this post to say thanks.

    Don't forget to mark this thread SOLVED by going to the "Thread Tools" drop down list above your first post and choosing solved.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 5
    Last Post: 05-19-2014, 06:34 PM
  2. Replies: 5
    Last Post: 01-20-2014, 06:25 AM
  3. Import tables from all Word documents within a folder into excel
    By Milk Snake in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-17-2014, 12:03 PM
  4. Replies: 0
    Last Post: 01-10-2014, 02:33 PM
  5. How to create multiple word documents using data from multiple excel files.
    By Milan Kotus in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-14-2013, 12:07 PM
  6. $$$ Macro to copy data from excel into word tables (example documents attached)
    By dapsef in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-04-2013, 12:17 PM
  7. Inserting multiple excel files into multiple word documents
    By lwaldron in forum Word Programming / VBA / Macros
    Replies: 11
    Last Post: 10-02-2012, 05:34 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1