Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. Private Sub Document_ContentControlOnExit(ByVal CC As ContentControl, Cancel As Boolean)
  2. 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
  3. Select Case CC.Title
  4. Case "C1", "L1"
  5. CField = "C1"
  6. LField = "L1"
  7. RField = "R1"
  8. RCatField = "RR1"
  9.  
  10. Case "C2", "L2"
  11. CField = "C2"
  12. LField = "L2"
  13. RField = "R2"
  14. RCatField = "RR2"
  15.  
  16.  
  17.  
  18.  
  19. Case Else
  20. Exit Sub
  21. End Select
  22.  
  23. CText = Left(ActiveDocument.SelectContentControlsByTitle(CField).Item(1).Range.Text, 1)
  24. LText = Left(ActiveDocument.SelectContentControlsByTitle(LField).Item(1).Range.Text, 1)
  25. If Not IsNumeric(CText) Then
  26. With ActiveDocument.SelectContentControlsByTitle(RField)(1)
  27. .LockContents = False
  28. .Range.Text = ""
  29. .LockContents = True
  30. End With
  31. With ActiveDocument.SelectContentControlsByTitle(RCatField)(1)
  32. .LockContents = False
  33. .Range.Text = ""
  34. .LockContents = True
  35. End With
  36. End If
  37. If Not IsNumeric(LText) Then
  38. Exit Sub
  39. End If
  40. LRate = LText
  41. CRate = CText
  42. RRate = ((CRate * 3) + (LRate * 2)) * 4
  43. Select Case RRate
  44. Case Is < 41
  45. RCat = "Low"
  46. Case Is < 55
  47. RCat = "Moderate"
  48. Case Is < 70
  49. RCat = "High"
  50. Case Is >= 70
  51. RCat = "Catastrophic"
  52. End Select
  53.  
  54.  
  55.  
  56.  
  57. With ActiveDocument.SelectContentControlsByTitle(RField)(1)
  58. .LockContents = False
  59. .Range.Text = RRate
  60. .LockContents = True
  61. End With
  62. With ActiveDocument.SelectContentControlsByTitle(RCatField)(1)
  63. .LockContents = False
  64. .Range.Text = RCat
  65. .LockContents = True
  66. End With
  67. End Sub
  68.  
  69. Sub CondFormat()
  70.  
  71. ColorFormat "condition", wdBlack
  72.  
  73. 'you may add more conditions/words here. E. G ColorFormat "condition2", wdPurple
  74. End sub
  75.  
  76. Function ColorFormat(txt as string, bckColor as wdColorIndex)
  77.  
  78. Dim rng as word.range
  79. Set rng = activedocument.range(start:=0, end:=100)
  80.  
  81. With rng.find
  82. Do while.execute(findText:=txt, MatchWholeWord:=True, Forward:=True,) = True
  83. If rng.Tables.count > 0 Then Rng.Cells(1).Shading.BackgroundPatternColorIndex = bckColor
  84. End of
  85. Loop
  86. End with
  87. End function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement