View Single Post
 
Old 10-08-2015, 01:17 PM
flyboy3300 flyboy3300 is offline Windows 7 32bit Office 2010 32bit
Novice
 
Join Date: Oct 2015
Posts: 4
flyboy3300 is on a distinguished road
Default Word 2010 the requested member of the collection does not exist

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

Last edited by macropod; 10-08-2015 at 05:17 PM. Reason: Added code tags & formatting
Reply With Quote