+ Reply to Thread
Results 1 to 7 of 7

Macro to export word table data to excel

Hybrid View

  1. #1
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,138

    Re: Macro to export word table data to excel

    Since you hard code the Word table row/column, there's no need to iterate the row/columns.

    I think what you want is:
    Sub Extract()
        Dim wrdTbl As Table
        Dim RowCount As Long, ColCount As Long, i As Long, j As Long
        Dim NextRow As Long
        '~~> Excel Objects
        Dim oXLApp As Object, oXLwb As Object, oXLws As Object
    
        '~~> Set your table
        Set wrdTbl = Selection.Tables(1)
    
        '~~> Create a new Excel Applicaiton
        Set oXLApp = CreateObject("Excel.Application")
    
        '~~> Hide Excel
        oXLApp.Visible = False
    
        '~~> Open the relevant Excel file
        Set oXLwb = oXLApp.Workbooks.Open("C:\Users\sogorman\Desktop\Test.xlsx")
        '~~> Work with Sheet1. Change as applicable
        Set oXLws = oXLwb.Sheets(1)
            '~~> Put your code here to export the values of the Word Table
            '~~> cell to Excel Cell. Use the .Range.Text to get the value
            '~~> of that table cell as shown above and then simply put that
            '~~> in the Excel Cell
            With oXLws
                NextRow = .Cells(.Rows.Count, "C").End(-4162).Row + 1
                .Cells(NextRow, 2).Value = wrdTbl.Cell(4, 2).Range.Text
                .Cells(NextRow, 3).Value = wrdTbl.Cell(4, 4).Range.Text
                .Cells(NextRow, 4).Value = wrdTbl.Cell(5, 2).Range.Text
                .Cells(NextRow, 5).Value = wrdTbl.Cell(5, 4).Range.Text
                .Cells(NextRow, 6).Value = wrdTbl.Cell(2, 4).Range.Text
                .Cells(NextRow, 7).Value = wrdTbl.Cell(2, 2).Range.Text
                .Cells(NextRow, 8).Value = wrdTbl.Cell(3, 2).Range.Text
            End With
    
        '~~> Close and save Excel File
        oXLwb.Close savechanges:=True
    
        '~~> Cleanup (VERY IMPROTANT)
        Set oXLws = Nothing
        Set oXLwb = Nothing
        oXLApp.Quit
        Set oXLApp = Nothing
    
        MsgBox "DONE"
    
    End Sub
    David
    (*) Reputation points appreciated.

  2. #2
    Forum Contributor
    Join Date
    02-20-2014
    Location
    Ireland
    MS-Off Ver
    Excel 2013
    Posts
    108

    Re: Macro to export word table data to excel

    Hi David,

    Sorry about the slow response, this works perfect for me. thanks very much

    You seem to know your stuff so i might ask another question

    In my table in word i have some tick boxes, a yes and no box to be precise, would there be a way to link that to the excel table to return a yes or no?

    That would be very handy but i can work around it if need be,

    Again thanks for your last reply

    Simon

+ 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: 0
    Last Post: 02-20-2013, 09:57 AM
  2. Export data to the rigth word table
    By Duart in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-23-2012, 12:24 PM
  3. code to export excel table to word
    By mcope in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-26-2005, 10:05 AM
  4. export excel data to a word template using a macro
    By Ross1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-25-2005, 01:06 AM
  5. How to export table from Excel to WORD?
    By boroangel in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-30-2005, 03:55 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