Adding a Checkbox

D

Dave

Let me say up front that I am not a programmer but, that through the
kindness of strangers who post their Word macros on the Web and answer
questions, I've been able to pull together simple macros that meet my
needs.

My current question is how to add a checkbox to the beginning of each
paragraph in a new document that is developed by pulling the headings
from an existing document. I've put in a comment where the checkbox
needs to go. All of the examples I've found for adding a checkbox
don't work in this instance.

Thanks in advance

Sub PrintHeadings()

' Creates a new document with Heading XX
' style paragraphs only from active document.
' User prompted for max level XX.

Dim para As Paragraph, rng As Range
Dim DocA As Document, DocB As Document
Dim iLevel As Integer, iMaxLevel As Integer
Dim HeadCount As Integer

' Ask for max level
iMaxLevel = InputBox("Enter maximum level of Headings to Include:")
If iMaxLevel = 0 Then Exit Sub

Set DocA = ActiveDocument

' Create new document
Set DocB = Word.Documents.Add(DocA.AttachedTemplate.Name)

Set rng = DocB.Range
HeadCount = 0

'Include text from another file

For Each para In DocA.Paragraphs

DoEvents
iLevel = 0

' Check for Heading style
If para.Format.Style Like "Heading [0-9]" Then

iLevel = Val(Mid(para.Format.Style, 8))
' Check for acceptable level
If iLevel > 0 And iLevel <= iMaxLevel Then

HeadCount = HeadCount + 1

'Add an option button before each paragraph
'Use HeadCount as part of button name


rng.Collapse wdCollapseEnd
rng.Text = String((iLevel - 1) * 4, " ") & _
Format(iLevel) & ") " & para.Range.Text
End If

End If
Next para

End Sub
 
D

Dave

To add a checkbox in the first paragraph of the document, try this:

Dim myCtrl As InlineShape

Set myCtrl =
ActiveDocument.Range.Paragraphs(1).Range.InlineShapes.AddOLEControl _
    (ClassType:="Forms.Checkbox.1")
With myCtrl.OLEFormat.Object
    .Name = "Check1"
End With

Change "ActiveDocument.Range.Paragraphs(1).Range" for the Range object in
your code, making sure you collpase it or you will replace the range content
with a checkbox.

Also, change "Check1" to something like
"Check" & HeadCount

That is working!

Thank you very much,

dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top