Reputation: 1
I want to extract tables from word app to Excel,i write a program to do that and it works. now i want to generalize this program (in case i have n tables) using loops, please if have any idea about how, i'll be so thankful.
**Sub FF()
Dim WordApp As Word.Application
Dim WordDoc As Word.Document
Dim Fichier As String
Dim i As Integer
Dim j As Integer
Fichier = "C:\Users\Desktop\ME\ME1.docx"
Set WordApp = CreateObject("Word.Application")
WordApp.Visible = False
Set WordDoc = WordApp.Documents.Open(Fichier)
j = 1
WordDoc.Tables(1).Range.Copy
Cells(j, 1).Select
ActiveSheet.Paste
j = 20
WordDoc.Tables(2).Range.Copy
Cells(j, 1).Select
ActiveSheet.Paste
WordDoc.Close False
WordApp.Quit
End Sub**
Upvotes: 0
Views: 52
Reputation: 11755
This is untested, but it demonstrates what I mean from the above comments.
Dim CurrentRow As Long
CurrentRow = 1
For Each wdTable In WordDoc.Tables
wdTable.Range.Copy
With ActiveSheet
.Cells(CurrentRow, 1).Select
.Paste
End With
CurrentRow = CurrentRow + wdTable.Rows.Count + 1
Next
Upvotes: 1