-
Frosty,
So "sooner" was sooner rather than later. I am attempting to code for some more complex conditional formatting (at the request of one of my users now that the document is deployed). It made sense for me to clean up now.
If you have time (and I know that's asking a lot) please take a look at the code below. I tried to clean up the formatting and tried to come up with one logical construct, in this case Option 1 that you provided.
I have prioritized Tag over ShowingPlaceholderText. I hope what I did is what you were trying to point out. The code has the same functionality as the old code but appears much cleaner to me.
[vba]Private Sub Document_ContentControlOnExit(ByVal CC As ContentControl, Cancel As Boolean)
Dim oCC_Target As ContentControl
Select Case CC.Tag
Case "longname1"
If fnc_InInvalidLong(CC) Then
Cancel = True
'CC.Range.Select
End If
If CC.ShowingPlaceholderText = True Then
CC.Range.Shading.BackgroundPatternColor = wdColorRose
'highlight longname2 and longname3 only if longname1 is cleared AND longname2 and longname3 are cleared
Set oCC_Target = ActiveDocument.SelectContentControlsByTag("longname2").Item(1)
If oCC_Target.ShowingPlaceholderText = True Then
With oCC_Target
With .Range
.Shading.BackgroundPatternColor = wdColorRose
End With
End With
End If
Set oCC_Target = ActiveDocument.SelectContentControlsByTag("longname3").Item(1)
If oCC_Target.ShowingPlaceholderText = True Then
With oCC_Target
With .Range
.Shading.BackgroundPatternColor = wdColorRose
End With
End With
End If
Else
CC.Range.Shading.BackgroundPatternColor = wdColorAutomatic
'remove highlighting from longname2 and longname3 if text entered in longname1
Set oCC_Target = ActiveDocument.SelectContentControlsByTag("longname2").Item(1)
With oCC_Target
With .Range
.Shading.BackgroundPatternColor = wdColorWhite
End With
End With
Set oCC_Target = ActiveDocument.SelectContentControlsByTag("longname3").Item(1)
With oCC_Target
With .Range
.Shading.BackgroundPatternColor = wdColorWhite
End With
End With
End If
Case "longname2", "longname3"
If fnc_InInvalidLong(CC) Then
Cancel = True
'CC.Range.Select
End If
If CC.ShowingPlaceholderText = False Then
CC.Range.Shading.BackgroundPatternColor = wdColorWhite
Else
Set oCC_Target = ActiveDocument.SelectContentControlsByTag("longname1").Item(1)
If oCC_Target.ShowingPlaceholderText = False Then
CC.Range.Shading.BackgroundPatternColor = wdColorWhite
Else
CC.Range.Shading.BackgroundPatternColor = wdColorRose
End If
End If
Case "shortname"
If fnc_InInvalidShort(CC) Then
Cancel = True
'CC.Range.Select
End If
Case "voteauth"
If CC.ShowingPlaceholderText = True Then
CC.Range.Shading.BackgroundPatternColor = wdColorRose
Else
'This is the CC that you are going to manipulate while processing the special case CC
'P.S. it would be nice if you used distintive titles and tabs (e.g., Voting Authority)
Set oCC_Target = ActiveDocument.SelectContentControlsByTag("voteauthin").Item(1)
If CC.Range.Text = "Sole" Then
'You really don't even want the CC to show. To bad there isn't a CC.Visible property.
With oCC_Target
.LockContents = False
With .Range
.Text = " " 'So it isn't showing placeholder text
.Shading.BackgroundPatternColor = wdColorAutomatic
End With
'To deal with the shmucks.
' .LockContents = True
End With
'Move to the next CC of interest
ActiveDocument.SelectContentControlsByTag("acmtype").Item(1).Range.Select
Else
With oCC_Target
.LockContents = False
With .Range
.Text = ""
.Shading.BackgroundPatternColor = wdColorRose
End With
End With
End If
End If
Case "Date1", "Date2", "Date3"
CC.Range.Shading.BackgroundPatternColor = wdColorWhite
Case Else
If CC.ShowingPlaceholderText = True Then
CC.Range.Shading.BackgroundPatternColor = wdColorRose
Else
CC.Range.Shading.BackgroundPatternColor = wdColorWhite
End If
End Select
End Sub[/vba]
As a random aside, I disabled the locking of voteauthin as that was no longer needed. If this was locked and a user clicked in it (because it was technically still there but with no text or highlighting) then they would get an error message and would be promted to debug. That whole routine freaks my users out. It was easier to have them be able to click in that cell by accident and have nothing happen. No one will type in there anyway. I agree with Greg that it would nice to have a CC.Visible command of some kind to just make the whole content control disappear.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules