I am trying to copy tables from one word document to other word document one by one.
On running the Macro, the first table is copied to other document and then it is throwing following Error
Run-time error '5941' The requested member of the collection does not exist.
Below is my program
Sub copyTable()
Dim TotalTables As Integer
TotalTables = ActiveDocument.Tables.Count
i = 1
Do While (i < TotalTables)
Set theTable = ActiveDocument.Tables(i).Range
theTable.Select
Selection.Copy
Dim oTarget As Document
Set oTarget = Documents.Open("D:\Target.docx")
oTarget.Select
Selection.Collapse Direction:=wdCollapseStart
Selection.Paste
i = i + 1
Loop
End Sub
The error specified in the title occurs on this line of code:
Set theTable = ActiveDocument.Tables(i).Range
Any Help Would Be Much Appreciated.
oTarget
becomes theActiveDocument
, so on the second loop you're trying to copy a non-existent table from it, instead of from your original document. – BigBen