Results 1 to 1 of 1

Extract word tables (multiple files) into one excel sheet using VBA

Threaded View

  1. #1
    Registered User
    Join Date
    05-12-2016
    Location
    Stuttgart, Germany
    MS-Off Ver
    2010
    Posts
    1

    Extract word tables (multiple files) into one excel sheet using VBA

    Hey,

    I really would appreaciate if someone could help me with following problem.

    I have a macro which opens one word document and puts the 4th table into a excel sheet. I would like to add 2 functions.
    1. I have about 200 Word documents, i would like to open. Doing this with macro would save a lot of manual effort.
    Therefore i found the
    Multiselect function
    . But this allows me only to select multiple files. Something is missing ...




    2. the table is not always the 4th in the documents. Sometimes it is the 5th or the 6th so i can't fix it via counting the tables.... . I found the
    .find
    function. Is it possible to search the Table which starts with "übersicht" an select it to copy?


    Thanks alot for help.





    
    
    Sub ImportWordTable() Dim wdDoc As Object Dim wdFileName As Variant Dim tableNo As Integer 'table number in Word Dim iRow As Long 'row index in Excel Dim iCol As Integer 'column index in Excel Dim resultRow As Long Dim tableStart As Integer Dim tableTot As Integer On Error Resume Next ActiveSheet.Range("A:AZ").ClearContents wdFileName = Application.GetOpenFilename("Word files (*.docx;*doc),*.docx", , _ "Browse for file containing table to be imported", MulitSelect: = True) If wdFileName = False Then Exit Sub '(user cancelled import file browser) Set wdDoc = GetObject(wdFileName) 'open Word file With wdDoc tableNo = wdDoc.tables.Count tableTot = wdDoc.tables.Count If tableNo = 0 Then MsgBox "This document contains no tables", _ vbExclamation, "Import Word Table" ElseIf tableNo > 1 Then tableNo = InputBox("This Word document contains " & tableNo & " tables." & vbCrLf & _ "Enter the table to start from", "Import Word Table", "4") End If resultRow = 1 For tableStart = 4 To 4 'tableTot With .tables(tableStart) 'copy cell contents from Word table cells to Excel cells For iRow = 1 To .Rows.Count For iCol = 1 To .Columns.Count Cells(resultRow, iCol) = WorksheetFunction.Clean(.cell(iRow, iCol).Range.Text) Next iCol resultRow = resultRow + 1 Next iRow End With resultRow = resultRow + 1 Next tableStart End With End Sub
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Extract word tables (multiple files) into excel using VBA
    By purple_milk in forum Excel Programming / VBA / Macros
    Replies: 25
    Last Post: 04-25-2024, 01:03 PM
  2. Replies: 2
    Last Post: 07-18-2013, 02:42 AM
  3. URGENT - Extracting / Importing certain tables from several word Files to Excel
    By pareshvm in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-17-2013, 09:29 AM
  4. Load multiple excel files into an excel sheet and extract data
    By Martijn79 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-03-2013, 06:08 PM
  5. [SOLVED] Need a macro to copy multiple word files with tables into excel workbook
    By neetharao in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-26-2012, 08:30 AM
  6. Extract headers from multiple Word files and list them in Excel
    By Towanda in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-30-2012, 12:09 PM
  7. Import tables from multiple Word files into a sheet of Excel
    By magdy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-27-2012, 03:53 AM

Tags for this Thread

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