Link to home
Start Free TrialLog in
Avatar of KineticNetworking
KineticNetworking

asked on

Inputting a Check Box object from a visual basic coding

I am working on a word 2003 file that has visual basic coding in it.  I already have coding that asks the user questions and puts the data throughout the document.  The client has asked if a check box can be inserted into the word document from the visual basic code.  Is this possible and if it is, can i have an example of the code?
Avatar of SStory
SStory
Flag of United States of America image

With your cursor at the desired position:

    Selection.Range.ContentControls.Add (wdContentControlCheckBox)
It depends on what type of checkbox.

This will add an ActiveX checkbox at the start of the active document
Sub InsActiveXCheckBox()
Dim ilsh As InlineShape
Dim rng As Range

Set rng = ActiveDocument.Range(0, 0)
Set ilsh = ActiveDocument.InlineShapes.AddOLEControl("Forms.Checkbox.1", rng)
End Sub

Open in new window

and this will add a Forms checkbox
Sub InsFormsCheckBox()
Dim ffld As FormField
Dim rng As Range

Set rng = ActiveDocument.Range(0, 0)
Set ffld = ActiveDocument.FormFields.Add(rng, wdFieldFormCheckBox)
End Sub

Open in new window

Avatar of KineticNetworking
KineticNetworking

ASKER

I just need to be able to put a plain square in a specific position in the document so after they print it out they can write a check in the box on the paper themselves.  It doesn't need to be interactive in word.  Sorry for the confusion.
ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The position will be the same place every time if they hit yes to a question.  Most likely on page two of three of the document.
I don't know how to code for that. If you specify the position, then the code can be written to conform to that. If not, it will be somewhat random, or at least unlikely to  match the requirements.
GrahamSkan,
   Can this

    With ActiveDocument
        .Shapes.AddShape msoShapeRectangle, 50, 100, 15, 15, .Range(0, 0)
    End With

be coded to be place of page 3.  I tested this and after 700 points down it goes off the pages, or it seems like it.