Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple tables in word

Status
Not open for further replies.

Dashley

Programmer
Dec 5, 2002
925
US
Im writing some code in VB6 that uses word as a report generator.
I need at least 4 tables in the document but everytime I create a second table it nests in the first

I tried everyting I could think of or read on.
Can anyone help

Here's part of the code. Ive taken the cell ref's and text type out for brevity.
Thanks


Dan


Private Sub OPEN_MISS_WORD()

Set wrdapp = CreateObject("word.application")
Set wrddoc = wrdapp.Documents.Add
Set wrdsel = wrdapp.Selection

wrdapp.Documents.Open ("C:\pst2.dot")

With wrdsel


.Tables.Add Range:=wrdsel.Range, NumRows:=3, NumColumns:=5, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitFixed
.Tables.Add Range:=wrdsel.Range, NumRows:=3, NumColumns:=5, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitFixed

End With

wrddoc.SaveAs ("c:\pst2.doc")

wrdapp.Quit
Set wrdsel = Nothing
Set wrddoc = Nothing
Set wrdapp = Nothing



DoEvents

If ShellExecute(0, &quot;Open&quot;, &quot;C:\pst2.doc&quot;, &quot;&quot;, App.Path, SW_SHOWMAXIMIZED) < 33 Then
MsgBox &quot;An error occured opening the file.&quot;, vbInformation, &quot;Can't open File! It May be already open&quot;
End If

DoEvents
Screen.MousePointer = vbDefault

End Sub
 
What I do is insert a paragraph marker after each table.

I'm sorry I do not have time to elaborate but it is either .InsertParagraph or .TypeParagraph
 
I tried both and now I have a nested table with a paragraph in it???
 
try something like this

Code:
Dim app As Word.Application
Dim doc As Word.Document
Dim tbl As Word.Table
Dim i As Long

Set app = New Word.Application
Set doc = app.Documents.Add

For i = 5 To 9
    Set tbl = doc.Tables.Add(doc.Range.Characters.Last, 3, i)
    doc.Range.Characters.Last.InsertParagraphAfter
    Set tbl = Nothing
Next

app.Visible = True

MsgBox &quot;pause&quot;

doc.Close False
Set doc = Nothing

app.Quit
Set app = Nothing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top