Results 1 to 7 of 7
  1. #1
    4 Star Lounger
    Join Date
    Apr 2001
    Posts
    482
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Change color of table cell on exit from formfield (Word 2000 VBA)

    I have done lots of macros in Word 2000, but none involving FormFields.

    I have a list box formfield. When the item selected is "GREEN", I want the table cell containing this list box to change to color wdColorGreen. Same for RED and YELLOW.

    I have tried:

    MsgBox ActiveDocument.FormFields.Item("Dropdown2").Result

    and I get the result "GREEN".

    Then I try:

    If ActiveDocument.FormFields.Item("Dropdown2").Result = GREEN Then
    Selection.Cells.Shading.ForegroundPatternColor = wdColorGreen
    End If

    but it does not even satisfy the If. If I try to select the if result manually, I get the message that the command is not available.

    Obviously I have several problems with my method. Any ideas for how to do this right?

    Thanks!!
    Troy

  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Change color of table cell on exit from formfield (Word 2000 VBA)

    Have you tried putting GREEN in " marks so that the line reads
    If ActiveDocument.FormFields.Item("Dropdown2").Result = "GREEN" Then

    StuartR

  3. #3
    4 Star Lounger
    Join Date
    Apr 2001
    Posts
    482
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Change color of table cell on exit from formfield (Word 2000 VBA)

    Yep, that helped. And I was able to figure out the rest.

    Now just one more thing. I'd like to reuse this macro for the currently selected list box.

    How do I specify the current list box as opposed to specifying an item by name?

    Thanks!!
    Troy

  4. #4
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Change color of table cell on exit from formfield (Word 2000 VBA)

    Try

    Selection.Formfields(1)

    StuartR

  5. #5
    4 Star Lounger
    Join Date
    Apr 2001
    Posts
    482
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Change color of table cell on exit from formfield (Word 2000 VBA)

    Thanks!! That worked!!

    Now just one more question. I know I can make this work whenever you enter or exit the field. However, I would like to make this fire whenever the item selected in the list changes. You do not actually enter or leave the field when you select a different item in the drop-down list.

    Any ideas?

    Thanks!!
    Troy

  6. #6
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Change color of table cell on exit from formfield (Word 2000 VBA)

    Sorry, I don't know how that can be done - maybe someone else can help?

    Alternate approaches would use a Modeless dialog box or a toolbar menu instead of a formfield.

    StuartR

  7. #7
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Change color of table cell on exit from formfi

    I have read on this very board that you cannot do this with Word's FormField TextBox control. Instead, you have to use an ActiveX controls from the Control Toolbox if you want any events other than Enter and Exit.

Posting Permissions

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