Strongs
09-27-2007, 02:03 PM
Hi all,
I am copying text from table rows in multiple documents and pasting the result into a table in a main document. I am getting the error 5991 "Cannot access individual rows in this collection because the table has vertically merged cells."
the row that i am copying from will always be row 1 in table 2 for each and every document. Unfortunately though, some documents, evidently have merged rows whilst others do not.
I am using the following code snippet to copy from the document collection and pasting into the main document.
Is there a way to copy from a table with merged vertical rows and avoid this error?
'loop thru open docs except Section 2.doc and copy required cells and paste into Section 2
For i = 1 To Application.Documents.Count - 1
Documents(1).Activate
'disable macros in blah docs that conflict with this macro
WordBasic.DisableAutoMacros 1
ActiveDocument.Tables(2).Rows(1).Cells(1).Select
Selection.Copy
Documents("Section 2.doc").Activate
ActiveDocument.Tables(1).Rows.Last.Cells(1).Select
Selection.Paste
Documents(1).Activate
ActiveDocument.Tables(2).Rows(1).Cells(2).Select
Selection.Copy
Documents("Section 2.doc").Activate
ActiveDocument.Tables(1).Rows.Last.Cells(2).Select
Selection.Paste
ActiveDocument.Tables(1).Rows.Last.Select
Selection.InsertRowsBelow 1
Documents(1).Activate
ActiveDocument.Close savechanges:=wdDoNotSaveChanges
Next i
Any suggestions would be welcomed
Regards,
I am copying text from table rows in multiple documents and pasting the result into a table in a main document. I am getting the error 5991 "Cannot access individual rows in this collection because the table has vertically merged cells."
the row that i am copying from will always be row 1 in table 2 for each and every document. Unfortunately though, some documents, evidently have merged rows whilst others do not.
I am using the following code snippet to copy from the document collection and pasting into the main document.
Is there a way to copy from a table with merged vertical rows and avoid this error?
'loop thru open docs except Section 2.doc and copy required cells and paste into Section 2
For i = 1 To Application.Documents.Count - 1
Documents(1).Activate
'disable macros in blah docs that conflict with this macro
WordBasic.DisableAutoMacros 1
ActiveDocument.Tables(2).Rows(1).Cells(1).Select
Selection.Copy
Documents("Section 2.doc").Activate
ActiveDocument.Tables(1).Rows.Last.Cells(1).Select
Selection.Paste
Documents(1).Activate
ActiveDocument.Tables(2).Rows(1).Cells(2).Select
Selection.Copy
Documents("Section 2.doc").Activate
ActiveDocument.Tables(1).Rows.Last.Cells(2).Select
Selection.Paste
ActiveDocument.Tables(1).Rows.Last.Select
Selection.InsertRowsBelow 1
Documents(1).Activate
ActiveDocument.Close savechanges:=wdDoNotSaveChanges
Next i
Any suggestions would be welcomed
Regards,