Solved

Inputting a Check Box object from a visual basic coding

Posted on 2012-03-16
8
225 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Do you ever need to create a 20 page Word document for some testing purpose? Are you tired of copying & pasting old boring "lorem ipsum" text over and over again, increasing font size and line space in order to make the document 20+ pages long? Look…
This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

738 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