Greg,
The compile error is with the following code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
The code Document_ContentControlOnExit is an ambiguous name.
Here is the complete code including the code you provided for the highlighting:
Private Sub ResetButton_Click()
Dim bProtected As Boolean
Dim oFld As FormFields
Dim i As Long
Set oFld = ActiveDocument.FormFields
'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:="xxxxxx"
End If
For i = 1 To oFld.Count
With oFld(i)
.Select
If .Name <> "" Then
Dialogs(wdDialogFormFieldOptions).Execute
End If
End With
Next
'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:="xxxxx"
End If
End Sub
Private Sub Document_ContentControlOnExit( _
ByVal CC As ContentControl, Cancel As Boolean)
If CC.Tag = "longname1" Then
If (Not CC.ShowingPlaceholderText) And Len(CC.Range.Text) > 48 Then
MsgBox "Limit 48 characters per line."
CC.Range.Select
End If
End If
If CC.Tag = "longname2" Then
If (Not CC.ShowingPlaceholderText) And Len(CC.Range.Text) > 48 Then
MsgBox "Limit 48 characters per line."
CC.Range.Select
End If
End If
If CC.Tag = "longname3" Then
If (Not CC.ShowingPlaceholderText) And Len(CC.Range.Text) > 48 Then
MsgBox "Limit 48 characters per line."
CC.Range.Select
End If
End If
If CC.Tag = "shortname" Then
If (Not CC.ShowingPlaceholderText) And Len(CC.Range.Text) > 20 Then
MsgBox "Short Name must be 20 characters or less."
CC.Range.Select
End If
End If
End Sub
Sub ScratchMacro()
'A quick macro scratch pad created by Greg Maxey
Dim oTbl As Word.Table
Dim oCell As Word.Cell
Dim oCC As ContentControl
Set oTbl = ActiveDocument.Tables(1)
For Each oCell In oTbl.Range.Cells
If oCell.Range.ContentControls.Count > 0 Then
For Each oCC In oCell.Range.ContentControls
If oCC.ShowingPlaceholderText = True Then
oCell.Shading.BackgroundPatternColor = wdColorBrightGreen
'or
'oCell.Range.HighlightColorIndex = wdBrightGreen
End If
Next oCC
End If
Next oCell
End Sub
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Dim oRng As Word.Range
If ContentControl.ShowingPlaceholderText = False Then
Set oRng = ContentControl.Range
oRng.Cells(1).Shading.BackgroundPatternColor = wdColorAutomatic
End If
End Sub
I tried including your new Private Sub code as an additional If statement in the existing Document_ContentControlOnExit sub but get a 424 error by doing that.
I have also tried changing the name of either of the Subs but either get errors or code that doesn't do anything.
Thank you for your help,
Brian