Solved

Inputting a Check Box object from a visual basic coding

Posted on 2012-03-16
8
224 Views
Last Modified: 2012-03-28
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?
0
Comment
Question by:KineticNetworking
8 Comments
 
LVL 25

Expert Comment

by:SStory
ID: 37730374
0
 
LVL 10

Expert Comment

by:SANTABABY
ID: 37730498
With your cursor at the desired position:

    Selection.Range.ContentControls.Add (wdContentControlCheckBox)
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 37730532
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

0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:KineticNetworking
ID: 37739701
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.
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 37740252
It isn't clear how you want to define the specific position. This will add a square, anchored at the start of the document, 50 points from the left of the page, and 100 from the top.

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

Open in new window

0
 

Author Comment

by:KineticNetworking
ID: 37744527
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.
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 37744726
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.
0
 

Author Comment

by:KineticNetworking
ID: 37759242
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.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Authors who set out to write any sort of lengthy piece for online submission—be it a long question or comment on a technical form, an article, or a substantial blog entry—often find it useful to work up a draft in an editor other t…
This is written from a 'VBA for MS Word' perspective, but I am sure it applies to most other MS Office components where VBA is used.  One thing that really bugs me is slow code, ESPECIALLY when it's mine!  In programming there are so many ways to…
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question