Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-06-2015, 10:55 PM
gmayor's Avatar
gmayor gmayor is offline Macro to check dropdown value and increment a counter Windows 7 64bit Macro to check dropdown value and increment a counter Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
  #2  
Old 01-07-2015, 10:12 AM
rkferguson's Avatar
rkferguson rkferguson is offline Macro to check dropdown value and increment a counter Windows 8 Macro to check dropdown value and increment a counter Office 2007
Novice
Macro to check dropdown value and increment a counter
 
Join Date: Jan 2015
Posts: 5
rkferguson is on a distinguished road
Thumbs up Macro to check dropdown value and increment a counter

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
Reply With Quote
Reply

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 to check dropdown value and increment a counter 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
Macro to check dropdown value and increment a counter Check Box Macro Johnny thunder Word VBA 12 04-07-2011 04:47 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:56 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft