2014-09-18 43 views
0

我這段代碼運行在vb.net中打開一個word文檔在vb.net應用行動態添加到單詞表

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

如果表中已經存在嘗試 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 
+0

還是一樣的錯誤 – charlie 2014-09-18 20:17:15

+0

任何想法,爲什麼它不會是工作? – charlie 2014-09-18 20:22:44

+0

該表已經存在於文件中? – 2014-09-18 20:26:51