Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Jan 2004
    Location
    Las Vegas, Nevada, USA
    Posts
    342
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Macro to insert text (XP/2003)

    I'm fairly good at writing macros and using VBA in Excel, but do know that much about Word.

    I would like to have a CheckBox trigger a macro when the box is checked.
    When checked the macro would insert the cusor the next line below the checkbox and auto type in several sentences into the Word document. The sentences would be of a consistant statement. (I.e. "You have selected the above option which requires an additional form. See the form on document XXX").

    In Excel you use something like this to select a cell and insert typing, but I can not figure is this possible in Word.

    Range("D5").Select
    ActiveCell.FormulaR1C1 = "Now is the time for all good men."
    Range("D7").Select

    Time to ask the Expert - HELP

    Thanks

    Richard Spring
    Richard Spring

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Macro to insert text (XP/2003)

    What kind of check box are you using? The one from the Forms toolbar or the one from the Control Toolbox?

  3. #3
    3 Star Lounger
    Join Date
    Jan 2004
    Location
    Las Vegas, Nevada, USA
    Posts
    342
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Macro to insert text (XP/2003)

    Probably from the Control Toolbox since you can have a Sub:

    Private Sub CheckBox1_Click()

    End Sub

    However, I don't know the exact properties of both types of Checkboxes, therefore I need more information. What exactly is the purpose
    of having two different CheckBoxes and in what case would you use either?

    I am open to any suggestions. Just would like the CheckBox to run the macro.

    Thanks,

    Richard Spring
    Richard Spring

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Macro to insert text (XP/2003)

    The controls from the Forms toolbar are used in a document that has been protected for forms. Within protected sections (protection can be enabled/disabled on a section-by-section basis), the user can only edit form fields, the rest of the text is locked. Form fields are more limited than controls from the Control Toolbox, but they are native to Word, and can do a lot of things without using code.

    The Control Toolbox contains far more controls, so if you need them, go for it. But they are not native to Word, so you'll need code to do anything with them.

    I have attached a small demo with two dropdowns from the Forms toolbar instead of check boxes. If you select 'Yes' from one of the dropdowns in the first part of the document and press Tab (or click elsewhere), you'll see some text appear.
    To see how it is designed, unprotect the document (Tools | Unprotect document), and double click a dropdown to see its properties. The bookmark name is important because it is used in the line below, and it is essential that the check box 'Calculate on exit' is ticked.
    To see where the text in the line below the dropdown comes from, press Alt+F9 to see the field codes. There are fields that look like this:
    <code>
    { IF { Dropdown1 } = "No" "" "A whole lotta text here" }
    </code>
    The field brackets { } have been inserted by pressing Ctrl+F9, not by typing { and }.
    Press Alt+F9 again to hide the field codes.
    Select Tools | Protect Document... and click OK to protect the document again.
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •