I created a table. The table is beginning at the first line of the Document. My Problem is that i cant insert a line above the table. Everytime i try to add a Paragraph, the Paragraph gets inserted after the last table. Is there a way to insert the lin above the first table?
To illustrate my Problem:
My Code so far:
Dim oApp As Word.Application
Dim oDoc As Word.Document
oApp = CType(CreateObject("Word.Application"), Word.Application)
oDoc = oApp.Documents.Add()
Dim rng As Word.Range = oDoc.Range(0, 0)
rng.Font.Name = "Verdana"
rng.Font.Size = 16
Dim para As Word.Paragraph = oDoc.Paragraphs.Add()
para.Range.Text = "Factsheet"
Dim tlb6 As Word.Table = oDoc.Tables.Add(Range:=rng, NumRows:=1, NumColumns:=4)
Dim CurrentDateTime As Date = Date.Now
Dim CurrentDate As Date = New Date(CurrentDateTime.Year, CurrentDateTime.Month, CurrentDateTime.Day)
tlb6.Cell(1, 1).Range.Text = "Date"
tlb6.Cell(1, 1).Shading.BackgroundPatternColor = Word.WdColor.wdColorGray20
tlb6.Cell(1, 1).Borders.OutsideLineStyle = 1
tlb6.Cell(1, 2).Range.Text = CurrentDate
tlb6.Cell(1, 2).Borders.OutsideLineStyle = 1
tlb6.Cell(1, 3).Range.Text = "Issued by"
tlb6.Cell(1, 3).Shading.BackgroundPatternColor = Word.WdColor.wdColorGray20
tlb6.Cell(1, 3).Borders.OutsideLineStyle = 1
tlb6.Cell(1, 4).Range.Text = ""
tlb6.Cell(1, 4).Borders.OutsideLineStyle = 1
If you’re using Word 2010, this should do the job (although it is ugly and uses Select and ActiveDocument):
It checks to make sure the first Paragraph object is inside a table, and if it does, it adds a row of text above it.