View Single Post
 
Old 01-28-2023, 02:27 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Quote:
I would love to be able to create separate codes that I can keep in their own separate modules, rather than combining the code into one macro (makes it much more difficult for me to try to write the code - less streamlined, more complicated for a beginner VBA-er IMO)
Whilst it is laudable that you want to modularise the code, you are not ready to deal with those extra complexities. Also, you only get one bite of the event Document_ContentControlOnExit unless you go down the rabbit hole of Class Modules. The sensible way to make 'separate codes' would be to create functions where you pass across the variables. That would allow you to efficiently deal with the other sorts of edge cases that might be required (eg what if the content control for 'Type' isn't in a table cell).
In any event, your code is not sufficiently complex to require multiple Subs and trying to do so before you have a good grasp of the basics is expending effort in the wrong direction.
Code:
Private Sub Document_ContentControlOnExit(ByVal aCC As ContentControl, Cancel As Boolean)
  Select Case aCC.Title
    Case "Awaiting Response", "Response Received"
      If aCC.Checked = True Then
        aCC.Range.Paragraphs(1).Range.Font.ColorIndex = wdRed
      Else
        aCC.Range.Paragraphs(1).Range.Font.ColorIndex = wdBlack
      End If
    Case "Type"
      Select Case aCC.Range.Text
        Case "NCR"
          aCC.Range.Cells(1).Shading.BackgroundPatternColor = RGB(214, 227, 188)
        Case "CAR"
          aCC.Range.Cells(1).Shading.BackgroundPatternColor = RGB(182, 221, 232)
        Case "OFI"
          aCC.Range.Cells(1).Shading.BackgroundPatternColor = RGB(251, 212, 180)
        Case Else
          aCC.Range.Cells(1).Shading.BackgroundPatternColor = RGB(255, 255, 255)
      End Select
  End Select
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote