Andrew

Andrew

  • NA
  • 1
  • 0

Writing multiple Tables to Word from VB

Jul 11 2009 10:28 AM

hi all,
 
How someone can help with this question. I am trying to write a number of tables to Word. I can create the document and application and add a table, my problem arises when I want to seperate them. I believe this is something to do with the "range". The first table is set at range (0, 0), I then try to reset the range, or  try to insert some blank lines and reset the range. I have also tried to create a new range for each table but I get the same result everytime which is the new table gets inserted into the first cell.
I have done some serious brain damage reading MS help on ranges and how to reset them and also moving selections up on and down- nothing seem to work. Utimately I have 8 tables and I want one table on 8 seperate pages.
thanks for any help you can give
Imports
Microsoft.Office.Interop.Word
Imports
System.Runtime.InteropServices
Public
junk As New DataTable

Private Sub WriteTables()
Dim oApp As Application
Dim oDoc As Document
'Start a new document in Word
oApp =
CType(CreateObject("Word.Application"), Application)
oDoc = oApp.Documents.Add()
' Clear out any existing information.
' oDoc.Range.Delete()
' make the current documents the ActiveDocument
oDoc.Activate()
 
 
Dim rng As Range = oDoc.Range(0, 0)
rng.Font.Name = "Verdana"
rng.Font.Size = 16
Dim tlb As Table = oDoc.Tables.Add(Range:=rng, NumRows:= junk.Rows.Count, NumColumns:= junk.Columns.Count)
tlb.Range.Font.Name = "Arial"
tlb.Range.Font.Size = 20
 
With oApp.Selection
.SetRange(tlb.Range.End + 1, tlb.Range.End + 1)
.Collapse(WdCollapseDirection.wdCollapseEnd)
End With
' Dim i As Integer
' For i = 1 To 5
' oApp.Selection.MoveDown()
' Next
 
 

' rng = oApp.Selection.Range
' rng.SetRange(Start:=0, End:=8)
' rng.SetRange(Start:=rng.End + 3, End:=rng.End + 3)
Dim tlb1 As Table = oDoc.Tables.Add(Range:=rng, NumRows:=6, NumColumns:=6)
oApp.Visible =
True
 

End Sub
 

Answers (1)