请教,如何通过vb.net 获得word文档里的控件textbox 的值呢?
我在test.doc (word 2003)里添加了控件 Textbox,名称为box1,现在想给textbox里添加文字。用下面的代码,得的结果是:
“集合所要求的成员不存在”
代码片段为:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim missing = System.Reflection.Missing.Value
Dim wApp As Word.Application
wApp = New Word.Application
wApp.Visible = True
Dim wDoc As Word.Document
wDoc = wApp.Documents.Open(FileName:="D:\Backup\我的文档\test") '(打开指定文件)
Try
wDoc.FormFields("box1").Result = "test"
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical) '如果出错则显示出错信息并退出
Finally
End Try
wApp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(wApp)
wApp = Nothing
End Sub
请各位前辈指教!