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?
http://gregmaxey.mvps.org/word_tip_pages/add_interactive_toggle_objects_to_document.html
With your cursor at the desired position:
Selection.Range.ContentCon trols.Add (wdContentControlCheckBox)
Selection.Range.ContentCon
It depends on what type of checkbox.
This will add an ActiveX checkbox at the start of the active document
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
and this will add a Forms checkboxSub InsFormsCheckBox()
Dim ffld As FormField
Dim rng As Range
Set rng = ActiveDocument.Range(0, 0)
Set ffld = ActiveDocument.FormFields.Add(rng, wdFieldFormCheckBox)
End Sub
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
ASKER
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.
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.