![]() |
#1
|
|||
|
|||
![]()
Hi all, hopefully you can help, and hopefully this is even possible!
I have a 'checklist' document that utilises checkboxes, the idea being you tick a box depending on the piece of work you are doing (this is a multi-discipline document) Is it possible for a section/part of the document the change ie be highlighted once a checkbox has been ticked? Any help greatly appreciated ![]() |
#2
|
|||
|
|||
![]()
Yes, it is.
What kind of checkboxes? There are three kinds in Word. Content Control? Legacy Formfield? Active-X? |
#3
|
|||
|
|||
![]()
Hey, thanks for the quick reply, i am using content control (purely for aesthetic reasons at the moment..)
|
#4
|
||||
|
||||
![]()
In that case you will need a macro and a bookmark. Bookmark the text you want to highlight and call the Bookmark (say) BM1. Assuming the title of the checkbox control is Check1, the following macro goes in the ThisDocument module of the document. The macro files after you click outside the check box having checked or unchecked it.
You can add more case statements for other checkbox/bookmark combinations as required. Code:
Option Explicit Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean) Select Case ContentControl.Title Case Is = "Check1" If ContentControl.Checked = True Then ActiveDocument.Bookmarks("BM1").Range.HighlightColorIndex = wdYellow Else ActiveDocument.Bookmarks("BM1").Range.HighlightColorIndex = wdNoHighlight End If End Select End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#5
|
||||
|
||||
![]()
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 |
#6
|
|||
|
|||
![]() Quote:
|
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
DEsh | Word VBA | 2 | 10-06-2017 08:23 PM |
![]() |
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 |