Word Forms and Macros Question

S

shanbones

I have created a template form in Word 2002 (XP). In my form there is a
table. One of the table's columns contains a checkbox in each row. What I
would like to have happen is that when the user checks the checkbox the row
that it is in will become highlighted/shaded. I am assuming that I will need
to do this with a macro, but I am not sure. If there is an easier way that
would be great! I am a macro novice so any assistance would be greatly
appreciated.
 
D

Doug Robbins

Run the following macro on exit from each of the checkboxes:

Dim ffname As String
ffname = Selection.FormFields(1).Name
With ActiveDocument
.Unprotect
If .FormFields(ffname).CheckBox.Value = True Then
.Bookmarks(ffname).Range.Rows(1).Shading.BackgroundPatternColor =
wdColorAqua
Else
.Bookmarks(ffname).Range.Rows(1).Shading.BackgroundPatternColor =
wdColorAutomatic
End If
.Protect wdAllowOnlyFormFields, noreset
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
S

shanbones

Thank you for the info Doug. However, when I tried to run this macro Visual
Basic comes up with a "Compile Error: Syntax Error" message window and
hightlights the following portion of the macro:

.Bookmarks(ffname).Range.Rows(1).Shading.BackgroundPatternColor =

Any suggestions?
Thanks, Shannon
 
C

Charles Kenyon

A line got wrapped. The following line should be a part of this line. Look
for any others that end in = as well.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
S

shanbones

I have followed the instructions listed below and am now receiving a "Compile
Error: Invalid use of property" highlighting the following section -
..BackgroundPatternColor

The entire macro is currently as follows:

Sub Highlightwhenchecked()
'
' Highlightwhenchecked Macro
' Macro created 6/22/2005 by Shannon Cook
'
Dim ffname As String
ffname = Selection.FormFields(1).Name
With ActiveDocument
.Unprotect
If .FormFields(ffname).CheckBox.Value = True Then
.Bookmarks(ffname).Range.Rows(1).Shading.BackgroundPatternColor
wdColorAqua
Else
.Bookmarks(ffname).Range.Rows(1).Shading.BackgroundPatternColor
wdColorAutomatic
End If
.Protect wdAllowOnlyFormFields, noreset
End With

End Sub
 
C

Charles Kenyon

Deleting the = isn't the way. You need to continue the line. Something like
the following, which I have _not_ tried.

Dim ffname As String
ffname = Selection.FormFields(1).Name
With ActiveDocument
.Unprotect
If .FormFields(ffname).CheckBox.Value = True Then
.Bookmarks(ffname).Range.Rows(1).Shading.BackgroundPatternColor _
= wdColorAqua
Else
.Bookmarks(ffname).Range.Rows(1).Shading.BackgroundPatternColor _
= wdColorAutomatic
End If
.Protect wdAllowOnlyFormFields, noreset
End With
 
S

shanbones

PERFECT!

Thank you so very much for your help!

Charles Kenyon said:
Deleting the = isn't the way. You need to continue the line. Something like
the following, which I have _not_ tried.

Dim ffname As String
ffname = Selection.FormFields(1).Name
With ActiveDocument
.Unprotect
If .FormFields(ffname).CheckBox.Value = True Then
.Bookmarks(ffname).Range.Rows(1).Shading.BackgroundPatternColor _
= wdColorAqua
Else
.Bookmarks(ffname).Range.Rows(1).Shading.BackgroundPatternColor _
= wdColorAutomatic
End If
.Protect wdAllowOnlyFormFields, noreset
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top