Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-15-2018, 02:45 PM
Guessed's Avatar
Guessed Guessed is offline Checkbox Highlight Option Windows 10 Checkbox Highlight Option 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


I would set up the document so that the title of the CC is the same as the bookmark name. Then you wouldn't need a massive series of code to deal with every specific pairing of CC to bookmarked range.
Code:
Private Sub Document_ContentControlOnExit(ByVal aCC As ContentControl, Cancel As Boolean)
  Dim sName As String, lColour As Long
  If aCC.Type = wdContentControlCheckBox Then
    If aCC.Checked Then
      lColour = wdYellow
    Else
      lColour = wdNoHighlight
    End If
    sName = Replace(aCC.Title, " ", "")         'bookmark names can't have spaces
    If ActiveDocument.Bookmarks.Exists(sName) Then
      ActiveDocument.Bookmarks(sName).Range.HighlightColorIndex = lColour
    End If
  End If
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #2  
Old 04-13-2022, 04:10 PM
Cire Cire is offline Checkbox Highlight Option Windows 10 Checkbox Highlight Option Office 2019
Novice
 
Join Date: Apr 2022
Posts: 1
Cire is on a distinguished road
Talking

Quote:
Originally Posted by Guessed View Post
I would set up the document so that the title of the CC is the same as the bookmark name. Then you wouldn't need a massive series of code to deal with every specific pairing of CC to bookmarked range.
Code:
Private Sub Document_ContentControlOnExit(ByVal aCC As ContentControl, Cancel As Boolean)
  Dim sName As String, lColour As Long
  If aCC.Type = wdContentControlCheckBox Then
    If aCC.Checked Then
      lColour = wdYellow
    Else
      lColour = wdNoHighlight
    End If
    sName = Replace(aCC.Title, " ", "")         'bookmark names can't have spaces
    If ActiveDocument.Bookmarks.Exists(sName) Then
      ActiveDocument.Bookmarks(sName).Range.HighlightColorIndex = lColour
    End If
  End If
End Sub
Work like a charm! Thank you very much!
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Checkbox Highlight Option One Content Control Checkbox checks another Content Control Checkbox DEsh Word VBA 2 10-06-2017 08:23 PM
Checkbox Highlight Option Checkbox in Userform lukael Excel Programming 5 02-18-2014 05:20 AM
find - reading highlight - highlight all / highlight doesn't stick when saved bobk544 Word 3 04-15-2009 03:31 PM
macro on checkbox macrohelp Word VBA 0 03-06-2009 03:33 PM
highlight cell after checkbox flatk Word 0 01-25-2007 12:32 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:58 AM.


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