Drop down field formatting

K

Kwanjangnim

Happy New Year everyone

i have a good knowledge of word, but know nothing about using macros. I have
created a form with dropdown fields with 2 or more choices, i would like to
attach a macro (conditional format) to each choice of selection (within the
DD field) that will change current font attributes according to the users
choice. can anyone help?

example typical choices: DD field contains
1. Not selected (Arial)
2. SELECTED (Arial Black)

thanking you in advance for your help with this problem
colin
 
G

Greg Maxey

Something like this should do. Set the macro to run on exit from the
dropdown field:

Sub FormatResult()
Dim oFF As FormField
ActiveDocument.Unprotect
Set oFF = Selection.FormFields(1)
Select Case oFF.Result
Case Is = "Selected"
oFF.Range.Font.Name = "Arial Bold"
Case Is = "Not Selected"
oFF.Range.Font.Name = "Arial"
Case Else
'Do Nothing
End Select
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End Sub
 
B

Beth Melton

Out of curiosity, why did you elect to use: Case Is="Not Selected" instead
of Case "Not Selected"?

I've always seen Is be used for comparison operators in a Case statement.
Something like Case Is >50.

Also note that Select Case is case-sensitive so if SELECTED is in uppercase
in the dropdown then it needs to be the same in the macro.

Please post all follow-up questions to the newsgroup. Requests for
assistance by email can not be acknowledged.

~~~~~~~~~~~~~~~
Beth Melton
Microsoft Office MVP

Word FAQ: http://mvps.org/word
TechTrax eZine: http://mousetrax.com/techtrax/
MVP FAQ site: http://mvps.org/
 
G

Greg Maxey

Beth,

It was just an oversight. I initially started out with

Select Case oFF.Dropdown.Value
Case "Not Selected"

and got a type error

Then I typed in Case Is and the editor automatically changed that to Case Is
=
but I still got the type error. Then I realised that dropdown.value was a
numerica value and changed that to Select Case oFF.Result and just didn't
take the time to change the case statements.
 

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