Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word VBA

Status
Not open for further replies.

Fixzy

Programmer
Aug 31, 2004
3
0
0
SE
I have a word doc that I would like to automate a bit. But I cant figure out how to catch the changes in the word doc.

I want a series of checkboxes that the user can choose from. When he/she chooses one there is text inserted into the doc.

The command I use for this is..If ActiveDocument.FormFields("Kryss1").CheckBox.Value = True Then (and so on).
But this only work If I use a button that the user press after he/she has choosen the box.

Is there no command like Private Sub ActiveDocument_Onchange() that I can use???

/Fixzy
 
As long as you insert them from the Control Toolbox (View>Toolbars>Control Toolbox), the various controls that you can insert in a Word document each have their own set of events. The checkbox in particular has the Change event, which fires every time it gets checked or unchecked. Put your code inside this event.

Let me know if that does what you're after!

VBAjedi [swords]
 
VBAJedi is refering to ActiveX controls, which have a lot more events that can fire. In many ways they are superior to FormFields.

However, FormFields can certainly do what you are asking.

Simply write your actions as a Sub and make it the OnExit macro to the checkbox.

Sub Kryss1Checked()
If blah blah.Result = True
do stuff
End Sub

Right click the checkbox and select Properties. Select that Sub for the Run macro on Exit. When the user exits the checkbox (giving a result) the macro will run.



Gerry
 
Hi.

I knew about this way to do it..but if I would like the result to appear as soon as the user X the box...is there any way to make that happen or do I have to use VBA boxes?

/Fixzy
 
Go back to VBAJedi's suggestion. Use the controls from the Controls Toolbar, NOT the formfields toolbar.

The controls from the Control toolbar have a Change event. It fires immediately. So, yes, if you use a ActiveX Checkbox, you can use the Change to:

1. test the current value (checked or not)
2. if checked, do whatever it is you want to do.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top