Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-30-2023, 11:05 AM
cavals07 cavals07 is offline Change Text Colour/Box Shade if CheckBox is marked Windows 10 Change Text Colour/Box Shade if CheckBox is marked Office 2010
Novice
Change Text Colour/Box Shade if CheckBox is marked
 
Join Date: Jan 2023
Posts: 5
cavals07 is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
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
Thank you Andrew - for all your time and support. Your code is great, and I will continue to work on honing my skills in VBA. All the best to my fellow VBA users, I look forward to keeping involved in this community to progress with you all!
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Change Text Colour/Box Shade if CheckBox is marked Conditionally Colour/Shade Numeric Output Ranges E.Buttimer Mail Merge 1 03-25-2021 02:20 PM
Change text colour for content control labels? Toe Word 1 01-17-2019 08:45 AM
Change Text Colour in Cell Based on Text in Same Cell PMC11 Word VBA 1 11-14-2017 09:15 PM
Change Text Colour/Box Shade if CheckBox is marked Quickest way to change text to Arial size 11 specific colour BlueClearSky Word 6 11-22-2013 03:34 PM
How to change line height for marked text (in Word 2007)? ... as default for font? pstein Word 1 01-14-2012 10:15 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:43 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft