Results 1 to 20 of 71

Thread: Macro to highlight if certain Word table cells are blank

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #11
    VBAX Regular
    Joined
    Dec 2006
    Posts
    71
    Location
    So I now have the exceptions to the highlighting coded and working properly and I did clean up the code using Case as suggested by Greg.

    I have attempted to code my conditional formatting. I have managed to write code that compiles and doesn't generate any error messages when it runs but it also doesn't do anything (or at least what I want it to do).

    I have attached the OnExit macro with my modifications highlighted in red. Perhaps someone can find where the code is going wrong.

    [vba]Private Sub Document_ContentControlOnExit(ByVal CC As ContentControl, Cancel As Boolean)
    Dim oRng As Word.Range
    Dim oVoteAuth As Boolean
    If ActiveDocument.ProtectionType <> wdNoProtection Then
    ActiveDocument.Unprotect Password:="12345"
    End If
    Select Case CC.Tag
    Case "longname1", "longname2", "longname3"
    If (Not CC.ShowingPlaceholderText) And Len(CC.Range.Text) > 48 Then
    MsgBox "Limit 48 characters per line."
    Cancel = True 'CC.Range.Select
    End If
    Case "shortname"
    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
    Case "voteauth"
    If CC.Range.Text = "Jerry Lewis" Then
    oVoteAuth = True
    End If
    End Select
    If CC.ShowingPlaceholderText = False Then
    'Set oRng = CC.Range
    'oRng.Cells(1).Shading.BackgroundPatternColor = wdColorAutomatic
    CC.Range.Shading.BackgroundPatternColor = wdColorAutomatic
    Else
    If CC.Tag = "voteauthin" Then
    If oVoteAuth = True Then
    CC.Range.Shading.BackgroundPatternColor = wdColorAutomatic
    End If

    Else
    'Set oRng = CC.Range
    'oRng.Cells(1).Shading.BackgroundPatternColor = wdColorAutomatic
    CC.Range.Shading.BackgroundPatternColor = wdColorRose
    End If
    End If
    If ActiveDocument.ProtectionType = wdNoProtection Then
    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:="12345"
    End If
    End Sub
    [/vba]

    I am trying to have one text content control have no background color if another drop down content control has specified values selected even if the text content control has no text entered.

    I have attached the document again as I have modified some of the other code.
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •