-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrols.vba
61 lines (48 loc) · 1.74 KB
/
controls.vba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
' This code goes in the "ThisDocument" module under "Microsoft Word Objects."
' It handles content control exit event (best we can do for selection change)
' and populates a following rich edit control according to the dropdown selection,
' which identifies a bookmark.
Option Explicit
Private Sub OnExit_fCorrect(ByVal cc As ContentControl)
Dim rngSav As Range
Set rngSav = Selection.Range
' find the range of the (logical) line (i.e., paragraph)
cc.Range.Select
Selection.Collapse wdCollapseEnd
Selection.MoveStart wdCharacter, 1 ' otherwise colors the checkbox (sdt close?)
Selection.MoveEnd wdParagraph ' wdLine is the DL
Selection.MoveEnd wdCharacter, -1 ' back off paragraph mark
' set color
Dim ci As WdColorIndex
Dim chSym As String
If cc.Checked Then
ci = wdAuto
chSym = "*"
Else
ci = wdRed
chSym = "-"
End If
Selection.Range.Font.ColorIndex = ci
' find symbol (allow for space)
Dim rngSym As Range
Set rngSym = ActiveDocument.Range(cc.Range.End + 1, cc.Range.End + 2) ' skip the sdt close
If rngSym.Text = " " Then
rngSym.SetRange rngSym.Start + 1, rngSym.End + 1
End If
' update symbol
If rngSym.Text = "*" Or rngSym.Text = "-" Then
rngSym.Text = chSym
End If ' if we don't find an acceptable symbol, don't do anything
rngSav.Select
End Sub
Private Sub Document_ContentControlOnExit(ByVal cc As ContentControl, cancel As Boolean)
'Exit Sub ' uncomment to turn off for submission
If cc.Tag = "fCorrect" Then
OnExit_fCorrect cc
Exit Sub
End If
If Left(cc.Tag, 1) = "!" Then
cancel = Not OnExit_Delta(cc)
Exit Sub
End If
End Sub