Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2007

Tip: Looking for answers? Try searching our database.

Inserting nesting tables not working correctly

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jack - 06 Jan 2007 01:42 GMT
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
Klaus Linke - 06 Jan 2007 07:35 GMT
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

>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
[quoted text clipped - 22 lines]
> Any suggestions?
> Jack
Jack - 06 Jan 2007 20:28 GMT
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

> Hi Jack,
>
[quoted text clipped - 39 lines]
>> Any suggestions?
>> Jack
Klaus Linke - 06 Jan 2007 20:52 GMT
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

>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
[quoted text clipped - 48 lines]
>>> Any suggestions?
>>> Jack
Jack - 08 Jan 2007 01:13 GMT
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
> In Word2003/2007, the cell could be protected. But since it happens with a
> newly created table too, that seems out of the question.
[quoted text clipped - 57 lines]
>>>> Any suggestions?
>>>> Jack
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.