dj Quecke
dj Quecke

Reputation: 13

How do I set a Word Checkbox using the Interop?

I can set string fields:

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

This works fine:

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

But this doesn't work:

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

I just want to check a box on my Word form. I can't even find the "Range" property.

I've searched:

  1. Stack

  2. the object browser in VS Studio

  3. Bookmarks Interface

Upvotes: 1

Views: 1580

Answers (2)

Cindy Meister
Cindy Meister

Reputation: 25683

When working with form fields it's better to address the formfield object rather than the bookmark name. The bookmark name serves as the index value for the FormFields collection.

For example:

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

Upvotes: 0

Rich Michaels
Rich Michaels

Reputation: 1713

It looks like you might be indicating there is a bookmark that surrounds a Checkbox Content Control in your document? If that is true then to mark the Checkbox you'll need code such as this ...

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

Upvotes: 1

Related Questions