View Single Post
 
Old 08-12-2014, 01:00 PM
gmaxey gmaxey is offline Windows 7 32bit Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default Reply

The code runs here without error:

Is your password "Password"

Unless you are using formfields, there is no point in protecting for filling in forms. See: http://gregmaxey.com/word_tip_pages/...llin_form.html and the section "Restrict Editing"
Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Dim StrPwd As String
StrPwd = "Password"
With ContentControl
  If Len(.Title) < 4 Then Exit Sub
  If Left(.Title, 4) = "SHR1" Then
    If ActiveDocument.ProtectionType <> wdNoProtection Then ActiveDocument.Unprotect Password:=StrPwd
    Select Case .Range.Text
      Case "Red": .Range.Cells(1).Shading.BackgroundPatternColorIndex = wdRed
      Case "Yellow": .Range.Cells(1).Shading.BackgroundPatternColorIndex = wdYellow
      Case "Green": .Range.Cells(1).Shading.BackgroundPatternColorIndex = wdBrightGreen
      Case Else: .Range.Cells(1).Shading.BackgroundPatternColorIndex = wdNoHighlight
    End Select
    ActiveDocument.Protect wdAllowOnlyFormFields, True, StrPwd
  End If
  If Left(.Title, 4) = "SHR2" Then
    If ActiveDocument.ProtectionType <> wdNoProtection Then ActiveDocument.Unprotect Password:=StrPwd
    Select Case .Range.Text
      Case "Red": .Range.Cells(1).Shading.BackgroundPatternColorIndex = wdRed
      Case "Yellow": .Range.Cells(1).Shading.BackgroundPatternColorIndex = wdYellow
      Case "Green": .Range.Cells(1).Shading.BackgroundPatternColorIndex = wdBrightGreen
      Case Else: .Range.Cells(1).Shading.BackgroundPatternColorIndex = wdNoHighlight
    End Select
    ActiveDocument.Protect wdAllowOnlyFormFields, True, StrPwd
  End If
End With
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/