ich geb dir mal meinen gesamten code, so wies ich mal gemacht hab (vb.net):
Private Sub vWord()
Dim oWord As New Word.Application
Dim oDoc As New Word.Document
Dim oTable As Word.Table
Dim oPara1 As Word.Paragraph
Dim sFileName As String
Dim sSql As String
Dim oRs As New ADODB.Recordset
Dim i As Long
Dim sVersion As String
Try
sFileName = oStdFct.vOpenDialog(OpenFileDialog1)
oDoc = oWord.Documents.Open(FileName:=sFileName)
sSql = " *** sql select *** "
i = 2
oRs.Open(sSql, oConn)
sVersion = oRs(1).Value
While Not oRs.EOF
oDoc.Tables.Item(1).Rows.Add(oDoc.Tables.Item(1).Rows.Item(2))
If oRs(1).Value <> sVersion Then
oDoc.Tables.Item(1).Cell(2, 1).Range.Text = oRs(1).Value & vbNewLine & Format(Date.Now, "dd.MM.yyyy")
sVersion = oRs(1).Value
Else
If i = 2 Then
oDoc.Tables.Item(1).Cell(2, 1).Range.Text = oRs(1).Value & vbNewLine & Format(Date.Now, "dd.MM.yyyy")
Else
oDoc.Tables.Item(1).Cell(2, 1).Range.Text = oRs(1).Value
End If
End If
oDoc.Tables.Item(1).Cell(2, 2).Range.Text = oRs(0).Value
oDoc.Tables.Item(1).Cell(2, 3).Range.Text = oRs(2).Value
i = i + 1
oRs.MoveNext()
End While
oRs.Close()
Dim a, b, c As Object
oWord.Documents.Save(a,
oWord.Documents.Close(a, b, c)
Catch ex As Exception
MsgBox(Err.Description & vbNewLine & _
"Entweder ist das Worddokument bereits offen oder wurde nicht korrekt geschlossen.", MsgBoxStyle.Critical)
Exit Function
End Try
End Function[/code]