FormField.CheckBox(es)

R

Robert

I have modified and expanded the undermentioned vbHelp
code hoping to insert in a document some empty check
boxes to be checked with a pencil. I have achieved only
limited success because only the first CheckBox inserted
in the document is the desired size. The remainder are
displayed and printed in the default size (which I
thought I had turned off.)

How can I make all the Check Boxes the size set by the
Size Property, please?
______________________________
Sub Checkbox2()
' Macro to insert a Checkbox at end of Selection or at IP.
' Modified from VBA Help file. Call with ALT + (alpha)2
' Box shading is not visible in printed output.

Selection.Collapse Direction:=wdCollapseEnd
Set ffield = ActiveDocument.FormFields _
.Add(Range:=Selection.Range,Type:=wdFieldFormCheckBox)

ffield.Name = "Check_Box_1"

With ActiveDocument.FormFields("Check_Box_1").CheckBox
.AutoSize = False
.Size = 18
.Value = False 'Displays plain, empty box.
End With
End Sub

Heartiest thanks from Old England.

Robert.
 
D

Doug Robbins

Your code is trying to assign the same bookmark name to all of the
formfields that you are adding with it, which it cannot do because each
bookmark name must be unique. As a result, only the first one gets that
bookmark name and it is only to the formfield with that bookmark name that
you are trying to apply the formatting, it does not get applied to any of
the other formfields.

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 
R

Robert

My thanks to Doug Robbins for his penetrating analysis of
which I was in fact dimly aware. Unfortunately he
doesn't tell me whether my code can be modified to
achieve my goal and, if so, how - or whether a totally
different approach is needed, and if so, what? Nor,
indeed, whether my goal is unachievable. I am left not
knowing how to proceed.

Is is necessary to give a name to a CheckBox? How can I
add (say) 15 identical Checkboxes to a single page? I
realise that I am using them for a purpose unintended by
Microsoft, but there is nothing in the Symbol font which
can be pressed into service. Can anyone suggest the next
step for me, please? Many thanks.
 
D

Doug Robbins

For your purposes, a name is not necessary, therefore, try something like:

Selection.Collapse Direction:=wdCollapseEnd
Set ffield = ActiveDocument.FormFields _
.Add(Range:=Selection.Range,Type:=wdFieldFormCheckBox)
With ffield.CheckBox
.AutoSize = False
.Size = 18
.Value = False 'Displays plain, empty box.
End With


--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 

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