Inserting nesting tables not working correctly

J

Jack

I have 5 tables all the same size 5 rows by 7 columns. I have another
separate table called tblSub that I want to insert into any two empty cells
of each of the 5 main tables .
My code is as follows:
**********
Set tblSub = ActiveDocument.Tables(6)
tblSub.Select
Selection.Copy
For it = 1 To 5
iSubCount = 0
For Each oCell In ActiveDocument.Tables(it).Range.Cells
If oCell.Range.Text = Chr(13) & Chr(7) Then
'Cell is empty, store subtable
iSubCount = iSubCount + 1
oCell.Range.PasteAsNestedTable
If iSubCount = 2 Then Exit For
End If
Next oCell
Next it
*********
This code works correctly for 3 inserts. When it=2 and isubcount=2, I get
the run time error 4605 "The command is not available"
The command "pasteasnestedtable" is the culprit.
Each table does have at least two empty cells.
Any suggestions?
Jack
 
K

Klaus Linke

Hi Jack,

Works without error for me...

Maybe you could stick in an
oCell.Range.Select
(or run that in the immediate window when the macro errors out), to see the
problematic cell?

Is there some possible complication, say "Track changes" turned on?

The table could be damaged. Maybe convert the second table to text, and back
to table.

Regards,
Klaus
 
J

Jack

I did as you suggested-ocell.range.select but it made no difference. I have
deleted the second table and created another just for test and the same
thing happens. I not sure of track changes. I checked
document.trackrevisions and it is false.
When it does halt at the error, I can go back to the document and see that
under the edit command, that all the paste commands are greyed out. So why
this happens is still a mystery
Jack
 
K

Klaus Linke

In Word2003/2007, the cell could be protected. But since it happens with a
newly created table too, that seems out of the question.
I'd have offered that you mail me the document, but if it happens with a new
table, it probably also happens with a new document?

I'm fresh out of ideas, and hope somebody else will jump in.

:-( Klaus
 
J

Jack

I never got my original code to work but I did change to the following code
and it works correctly.
It is still a puzzle to me while the original code did not work
Jack
New Code:
ActiveDocument.Tables(6).select
Selection.Copy
For it = 1 To 5
iSubCount = 0
ActiveDocument.Tables(it).Range.Cells(1).range.select

do while isubcount<2
IF selection.Text = Chr(13) & Chr(7) Then
'Cell is empty, store subtable
iSubCount = iSubCount + 1
selection.pasteAsNestedTable
End If
selection.moveright unit:=wdcell
loop
next it
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top