![]() |
|
|
|
#1
|
||||
|
||||
|
The macro is intended to be run separately. If you want a macro to run on exit from the form field(s) then run the following on exit from and on entry to each form field
Code:
Option Explicit
Public rngFF As Word.Range
Public fldFF As Word.FormField
Public Sub DropDownColour()
Dim bProtected As Boolean
With GetCurrentFF
If .Type = wdFieldFormDropDown Then
'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
Select Case .Result
Case "A": .Range.Font.ColorIndex = wdRed
Case "B": .Range.Font.ColorIndex = wdYellow
Case "C": .Range.Font.ColorIndex = wdGreen
Case Else
End Select
'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, _
NoReset:=True, _
Password:=""
End If
End If
End With
lbl_Exit:
Exit Sub
End Sub
Public Function GetCurrentFF() As Word.FormField
Set rngFF = Selection.Range
rngFF.Expand wdParagraph
For Each fldFF In rngFF.FormFields
Set GetCurrentFF = fldFF
Exit For
Next fldFF
lbl_Exit:
Exit Function
End Function
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#2
|
||||
|
||||
|
So I was complicating things by trying to modify the "Counting" macro, to change font colors as well.
As I understand you suggestion, I should leave the counting macro alone (as I have it now, I am calling it via the quick access tool bar after the template is populated), and use the color changing macro on entry and exit from each bookmark/dropdown. May I ask why it should run on both entry and exit? It seems to me, the uninitiated, that running it on entry would cause issues or at least redundancy. That is, if run "on entry" the macro will change the font color per the initial value of the drop down "result", and on exit, it would change the font color per the value the user selects from the drop down list. Would it not be sufficient to just run it on exit? I am not challenging your guidance/advice, just trying to fully understand the logic. Thank you, very much. ![]() Fergie |
|
| Tags |
| bookmarks, word 2003, word vba macro |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Dropdown list, Macro | shield5 | Excel Programming | 7 | 10-27-2013 01:51 AM |
macro not working (on click increment)
|
gsrikanth | Excel Programming | 1 | 07-12-2012 07:40 AM |
| Check box macro help needed | Aflac | Word | 4 | 03-24-2012 07:11 PM |
| Macro to populate a text form field based on dropdown selection | koloa | Word | 0 | 10-20-2011 11:52 AM |
Check Box Macro
|
Johnny thunder | Word VBA | 12 | 04-07-2011 04:47 PM |