Consulting

Results 1 to 4 of 4

Thread: Same VB code not working for similar Content Controls with different CC titles

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Regular
    Joined
    Apr 2024
    Posts
    10
    Location

    Same VB code not working for similar Content Controls with different CC titles

    I have a Word document (attached) where the user is to enter information about the status of several tasks. For each task the user is to select the status of the task from a content control dropdown list. Options are: "No issues" or "Issues found". If "Issues found" is selected, the user is to provide a description of the issue for that task in a textbox.

    While the code works for the first task, it does not work for the content controls in the second task

    What am I doing wrong?

    Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)
      If CCtrl.Title = "CCDDL" Then
         With CCtrl.Range
           Select Case .Text
              Case "Issues found"
                .Font.ColorIndex = wdRed
                 ActiveDocument.SelectContentControlsByTitle("CCTB")(1).SetPlaceholderText , , "Enter issues here"
              Case Else
                .Font.ColorIndex = wdBlack
                ActiveDocument.SelectContentControlsByTitle("CCTB")(1).SetPlaceholderText , , ChrW(8203)
                ActiveDocument.SelectContentControlsByTitle("CCTB")(1).Range.Text = vbNullString
           End Select
         End With
      End If
    End Sub
    
    
    Private Sub Document_ContentControlOnExit2(ByVal CCtrl As ContentControl, Cancel As Boolean)
      If CCtrl.Title = "CCDDL2" Then
         With CCtrl.Range
           Select Case .Text
              Case "Issues found"
                .Font.ColorIndex = wdRed
                 ActiveDocument.SelectContentControlsByTitle("CCTB2")(1).SetPlaceholderText , , "Enter issues here"
              Case Else
                .Font.ColorIndex = wdBlack
                ActiveDocument.SelectContentControlsByTitle("CCTB2")(1).SetPlaceholderText , , ChrW(8203)
                ActiveDocument.SelectContentControlsByTitle("CCTB2")(1).Range.Text = vbNullString
           End Select
         End With
      End If
    End Sub
    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
  •