Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Private Sub Document_ContentControlOnExit(ByVal CC As ContentControl, Cancel As Boolean)
- Dim CField As String, LField As String, RField As String, CText As String, LText As String, CRate As Double, LRate As Double, RRate As Double, RCat As String, RCatField As String
- Select Case CC.Title
- Case "C1", "L1"
- CField = "C1"
- LField = "L1"
- RField = "R1"
- RCatField = "RR1"
- Case "C2", "L2"
- CField = "C2"
- LField = "L2"
- RField = "R2"
- RCatField = "RR2"
- Case Else
- Exit Sub
- End Select
- CText = Left(ActiveDocument.SelectContentControlsByTitle(CField).Item(1).Range.Text, 1)
- LText = Left(ActiveDocument.SelectContentControlsByTitle(LField).Item(1).Range.Text, 1)
- If Not IsNumeric(CText) Then
- With ActiveDocument.SelectContentControlsByTitle(RField)(1)
- .LockContents = False
- .Range.Text = ""
- .LockContents = True
- End With
- With ActiveDocument.SelectContentControlsByTitle(RCatField)(1)
- .LockContents = False
- .Range.Text = ""
- .LockContents = True
- End With
- End If
- If Not IsNumeric(LText) Then
- Exit Sub
- End If
- LRate = LText
- CRate = CText
- RRate = ((CRate * 3) + (LRate * 2)) * 4
- Select Case RRate
- Case Is < 41
- RCat = "Low"
- Case Is < 55
- RCat = "Moderate"
- Case Is < 70
- RCat = "High"
- Case Is >= 70
- RCat = "Catastrophic"
- End Select
- With ActiveDocument.SelectContentControlsByTitle(RField)(1)
- .LockContents = False
- .Range.Text = RRate
- .LockContents = True
- End With
- With ActiveDocument.SelectContentControlsByTitle(RCatField)(1)
- .LockContents = False
- .Range.Text = RCat
- .LockContents = True
- End With
- End Sub
- Sub CondFormat()
- ColorFormat "condition", wdBlack
- 'you may add more conditions/words here. E. G ColorFormat "condition2", wdPurple
- End sub
- Function ColorFormat(txt as string, bckColor as wdColorIndex)
- Dim rng as word.range
- Set rng = activedocument.range(start:=0, end:=100)
- With rng.find
- Do while.execute(findText:=txt, MatchWholeWord:=True, Forward:=True,) = True
- If rng.Tables.count > 0 Then Rng.Cells(1).Shading.BackgroundPatternColorIndex = bckColor
- End of
- Loop
- End with
- End function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement