我正在运行此代码以在vb.net中打开word文档
Dim oWord_detail As New word.Application
Dim oDoc_detail As word.Document
oWord_detail.Visible = True
oDoc_detail = oWord_detail.Documents.Open("c:\integra-billing\integra-invoice-detail.docx", False, False)
然后我使用此行向我的word文档添加新行
oDoc_detail.Tables(1).Rows.Add()
但是当它运行时,上面的行显示错误:
The requested member of the collection does not exist
答案 0 :(得分:0)
如果表已存在,请尝试 oDoc_detail.Tables.Item(1).Rows.Add()
然后将文字添加到单元格
Dim oWord_detail As New Word.Application
Dim oDoc_detail As Word.Document
oWord_detail.Visible = True
oDoc_detail = oWord_detail.Documents.Open("C:\Dati\Temp\test.docx", False, False)
oDoc_detail.Tables.Item(1).Rows.Add()
For r = 1 To 1 'your row
For c = 1 To 3
oDoc_detail.Tables.Item(1).Cell(r, c).Range.Text = "r" & r & "c" & c
Next
Next