如何使用 Interop 设置 Word 复选框?

How do I set a Word Checkbox using the Interop?

我可以设置字符串字段:

Dim msWord As New Microsoft.Office.Interop.Word.Application
Dim doc As Microsoft.Office.Interop.Word.Document

这很好用:

doc.Bookmarks("InitialsSecurityClass108").Range.Text = _ WordDocDAta.InitialsSecurityClass108

但这行不通:

doc.Bookmarks("chkSecurityClass101").Range.Text = .chkSecurityClass101

我只想选中我的 Word 表单上的一个框。我什至找不到 "Range" 属性.

我搜索过:

  1. 堆栈

  2. VS Studio 中的对象浏览器

  3. Bookmarks Interface

您似乎是在指示文档中的复选框内容控件周围有一个书签?如果是这样,那么要标记复选框,您将需要这样的代码 ...

doc.Bookmarks("chkSecurityClass101").Range.ContentControls(1).Checked = True

在处理表单域时,最好处理表单域对象而不是书签名称。书签名称用作 FormFields 集合的索引值。

例如:

doc.FormFields("InitialsSecurityClass108").Result = "Text in textbox"
doc.FormFields("chkSecurityClass101").CheckBox.Value = true