I am using the following code with several other codes in Word 2010. If I do not have any other codes or this one is the first code then it works but as soon as I add others before this one I get the error msg the requested member of the collection does not exist
I am trying to color the background of the drop down box when I select the different items
Code:
Option Explicit
Dim i As Long
Private Sub Document_Open()
ActiveDocument.Bookmarks("DropDown").Range.Select
Call Index
End Sub
Sub Index()
i = Replace(Selection.FormFields(1).Range.Bookmarks(1).Name, "DropDown", "")
End Sub
Sub RiskClassification()
Dim sText As String, oFld As FormField
With ActiveDocument
Set oFld = .FormFields("Dropdown" & i)
sText = oFld.Result
If .ProtectionType <> wdNoProtection Then .Unprotect Password:=""
With oFld.Range
Select Case sText
Case Is = " " 'white
.Font.Color = wdColorWhite
.Shading.BackgroundPatternColor = wdColorWhite
Case Is = "1A" 'red
.Font.Color = wdColorBlack
.Shading.BackgroundPatternColor = wdColorRed
Case Is = "2A" 'red
.Font.Color = wdColorBlack
.Shading.BackgroundPatternColor = wdColorRed
Case Is = "3A" 'orange
.Font.Color = wdColorBlack
.Shading.BackgroundPatternColor = wdColorOrange
Case Is = "4A" 'yellow
.Font.Color = wdColorBlack
.Shading.BackgroundPatternColor = wdColorYellow
Case Is = "1B" 'red
.Font.Color = wdColorBlack
.Shading.BackgroundPatternColor = wdColorRed
Case Is = "2B" 'orange
.Font.Color = wdColorBlack
.Shading.BackgroundPatternColor = wdColorOrange
Case Is = "3B" 'yellow
.Font.Color = wdColorBlack
.Shading.BackgroundPatternColor = wdColorYellow
Case Is = "4B" 'blue
.Font.Color = wdColorBlack
.Shading.BackgroundPatternColor = wdColorBlue
Case Is = "1C" 'orange
.Font.Color = wdColorBlack
.Shading.BackgroundPatternColor = wdColorOrange
Case Is = "2C" 'yellow
.Font.Color = wdColorBlack
.Shading.BackgroundPatternColor = wdColorYellow
Case Is = "3C" 'blue
.Font.Color = wdColorBlack
.Shading.BackgroundPatternColor = wdColorBlue
Case Is = "4C" 'green
.Font.Color = wdColorBlack
.Shading.BackgroundPatternColor = wdColorGreen
Case Is = "1D" 'yellow
.Font.Color = wdColorBlack
.Shading.BackgroundPatternColor = wdColorYellow
Case Is = "2D" 'blue
.Font.Color = wdColorBlack
.Shading.BackgroundPatternColor = wdColorBlue
Case Is = "3D" 'green
.Font.Color = wdColorBlack
.Shading.BackgroundPatternColor = wdColorGreen
Case Is = "4D" 'green
.Font.Color = wdColorBlack
.Shading.BackgroundPatternColor = wdColorGreen
End Select
End With
.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End With
End Sub