Re: Inserting multiple tables into a document

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



The trick is to insert a paragraph after each table.

Dim pTable As Word.Table
Dim pIndex As Long
Dim pRange As Word.Range

For pIndex = 1 To 5

Set pRange = ActiveDocument.Range(ActiveDocument.Content.End - 1,
ActiveDocument.Content.End)
Set pTable = ActiveDocument.Tables.Add(Range:=pRange, NumRows:=2,
NumColumns:=4)
ActiveDocument.Content.InsertParagraphAfter

Next



"Peter" <Peter@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:1541922B-F519-4A1A-8BDB-A1CC81B7B127@xxxxxxxxxxxxxxxx
>I am developing a VBA program to process a number of tables in a word
> document by sorting each table then transferring the contents of each
> sorted
> table to a new table (with changed layout) in another document.
>
> My code successfully sorts the tables in the source document, and adds the
> first new table in the new document Ok, but all subsequent new tables
> appear
> to be added as nested within the first table of the new document because
> my
> insertion point appears to remain with the range of the first table.
>
> How do I programmatically change the Range Selection/Insertion point each
> time to go to a new point outside the end of the last table inserted so
> that
> when I do a Tables.Add statement it inserts the next table as a completely
> new table following the previous one? I have tried adding code:
> Selection.MoveDown Unit:=wdLine, Count =1 , but this appears to just
> extend the existing range of the current table.
>
> --
> Peter WA


.



Relevant Pages

  • Re: Moving to next field with F11 in protected document
    ... a file with the name of the selection and inserts one space and then ... insertion point would move to the location following "postmarked on" ... Dim rgeField As Range ... Dim lngStart As Long ...
    (microsoft.public.word.vba.beginners)
  • Re: Excel- Inserting a varying number of rows
    ... Assumes data in Col A and values in Col B - Will finish the first time it hits a ... Dim numRows As Integer ... > to use the cell value of B2 to direct the insertion of 5 blank rows ... > of blank rows directly beneath its row. ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Email Body & HTMLBody From Excel
    ... "Text Below Range Insertion." ... I am using Excel 2003. ... Dim objOL As New Outlook.Application ... Dim rng As Range ...
    (microsoft.public.excel.programming)
  • Re: Inserting multiple tables into a document
    ... Thanks Jezebel your sample code supplied has provided the answer. ... > Dim pTable As Word.Table ... >> table to a new table (with changed layout) in another document. ... >> insertion point appears to remain with the range of the first table. ...
    (microsoft.public.word.vba.general)
  • Re: Question about SqlTransaction
    ... > there's error occur in Detail insertion. ... > Dim da As SqlDataAdapter ... > Dim myTrans As SqlTransaction ... then rollback all if there's any error. ...
    (microsoft.public.dotnet.framework.adonet)