+ Reply to Thread
Results 1 to 6 of 6

Macro to Export Word Tables to Excel

Hybrid View

  1. #1
    Registered User
    Join Date
    11-09-2009
    Location
    london, england
    MS-Off Ver
    Excel 2010
    Posts
    52

    Re: Macro to Export Word Tables to Excel

    Hi WesternGal

    I too gave your original code a go using Excel 2010 on Windows 7 and it worked for both doc and docx files. I was unable to replicate the error.
    However, I had a quick look online and found this useful msdn resource that describes "Programmatically Selecting Files in Excel for Windows and Excel for the Mac" http://msdn.microsoft.com/en-us/libr...FileNameMethod

    Hope the msdn link is of some help to you.
    Please click * if the answer was helpful.

  2. #2
    Registered User
    Join Date
    05-17-2013
    Location
    South Carolina
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Macro to Export Word Tables to Excel

    Found an answer: on a MAC, the line has to read:
    wdFileName = Application.GetOpenFilename( )
    There were multiple other errors in the code I had copied, but I found the correct text to loop through all tables in Word and import them to excel on this thread:
    HTML Code: 
    Sub ImportWordTable3()
    'Import all tables to a single sheet
    Dim wdDoc As Object
    Dim wdFileName As Variant
    Dim TableNo As Integer 'table number in Word
    Dim iRow As Long 'row index in Word
    Dim jRow As Long 'row index in Excel
    Dim iCol As Integer 'column index in Excel
    
    wdFileName = Application.GetOpenFilename()
    
    If wdFileName = False Then Exit Sub '(user cancelled import file browser)
    
    Set wdDoc = GetObject(wdFileName) 'open Word file
    
    With wdDoc
        If wdDoc.tables.Count = 0 Then
            MsgBox "This document contains no tables", _
                vbExclamation, "Import Word Table"
        Else
            jRow = 0
            Sheets.Add after:=Sheets(Worksheets.Count)
            For TableNo = 1 To wdDoc.tables.Count
                With .tables(TableNo)
    'copy cell contents from Word table cells to Excel cells
                    For iRow = 1 To .Rows.Count
                        jRow = jRow + 1
                        For iCol = 1 To .Columns.Count
                            On Error Resume Next
                            ActiveSheet.Cells(jRow, iCol) = WorksheetFunction.Clean(.cell(iRow, iCol).Range.Text)
                            On Error GoTo 0
                        Next iCol
                    Next iRow
                End With
                jRow = jRow + 1
            Next TableNo
        End If
    End With
    Set wdDoc = Nothing
    End Sub

  3. #3
    Registered User
    Join Date
    11-23-2014
    Location
    Switzerland
    MS-Off Ver
    Word, Excel, Outlook, Power Point - all 2010
    Posts
    1

    Re: Macro to Export Word Tables to Excel

    Thanks a million, Western Gal. I had searched for days and worked sooo many hours to try to solve this problem. With your code plus a couple of tiny twiddles to it to import data from just one single-line table, it ran perfectly on my Windows PC.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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