Import Table from Word Document

GRCArizona

Board Regular
Joined
Apr 24, 2010
Messages
95
Hi -

I've got a 91 page Word document that has 52 tables. I'm looking for an Excel macro that will open up the Word document and grab the contents of Table #32 only and paste it back into an Excel worksheet. I've searched the thread and have found out how to open the Word document as well as "find" table #32, but can't seem to be able to retrieve the contents from Table #32 and put it back into Excel. Not sure if this helps, but Table #32 is always on Page 35. The other x-factor is that Table 32 has a graph along with the normal table info (rows and columns of data). (I found that the graph appears to be included in Table 32, b/c another rmacro I came across to assist in finding the Table #, highlights both the graph and data). Hope that makes sense. If possible, I would like the graph to come over as well.

Any help is appreciated!
thanks,
GRC
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hi
See if this example is useful:

Code:
' Excel module
Sub Import_from_Word()
Dim wap As Object, wdoc As Word.Document, r%, c%, tn%, ish As Word.InlineShape, n%


Set wap = CreateObject("Word.Application")
wap.Visible = True
Set wdoc = wap.documents.Open(ThisWorkbook.Path & "\MessageW.docm") ' your file name here
tn = 3                                                              ' table index
For r = 1 To wdoc.Tables(tn).Rows.Count
    For c = 1 To wdoc.Tables(tn).Columns.Count
        ActiveSheet.Cells(r, c).Value = wdoc.Tables(tn).Cell(r, c).Range.Text
    Next
Next
n = 1
For Each ish In wdoc.Tables(tn).Range.InlineShapes
    ish.Range.Copy
    ActiveSheet.Paste Cells(n * 7, n * 7)
    n = n + 1
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,249
Messages
6,171,031
Members
452,374
Latest member
keccles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top