Adoray

module

Aug 17th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. Option Explicit
  2. Public p_ThisApp As clsThisApp
  3. Sub AutoExec()
  4. InitiateAppClass
  5. End Sub
  6. Sub AutoOpen()
  7. InitiateAppClass
  8. End Sub
  9. 'Call this pocedure to initialize the clase
  10.  
  11. Public Sub InitiateAppClass()
  12. Set p_ThisApp = Nothing
  13. Set p_ThisApp = New clsThisApp
  14. lbl_Exit:
  15. Exit Sub
  16. End Sub
  17.  
  18. Sub BuildControls()
  19. Dim oPopUp As CommandBarPopup
  20. Dim oCtr As CommandBarControl
  21. Dim oBtn As CommandBarButton
  22. Dim lngIndex As Long
  23. Dim lngMarker As Long
  24. Dim lngPosit As Long
  25.  
  26. CustomizationContext = ThisDocument.AttachedTemplate
  27. 'Prevent double customization
  28. Set oPopUp = CommandBars.FindControl(Tag:="BuiltInAC")
  29. If Not oPopUp Is Nothing Then GoTo lbl_Exit
  30. On Error GoTo lbl_Exit
  31. 'Determine where the "Ignore All" control is located. This tells us how many suggested spellings are in the context menu.
  32. lngMarker = CommandBars("Spelling").Controls("&Ignore All").Index
  33. 'Add the built-in AutoCorrect popup
  34. Set oPopUp = CommandBars("Spelling").Controls.Add(msoControlPopup, 30096, , CommandBars("Spelling").Controls("&Hyperlink...").Index, 1)
  35. With oPopUp
  36. .Tag = "BuiltInAC"
  37. .BeginGroup = True
  38. End With
  39. 'I would have thought that the built-in popup would include the suggested spelling and the AutoCorrect options dialo, but it doesn't.
  40. 'Yuck. This means that they will have to be fudged and added\removed with each selection change :-(
  41. On Error GoTo Err_Posit
  42. lngPosit = 1
  43. Err_Posit_Reentry:
  44. For lngIndex = lngPosit To lngMarker - 1
  45. Set oBtn = oPopUp.Controls.Add(msoControlButton, CommandBars("Spelling").Controls(lngIndex).ID)
  46. With oBtn
  47. .Caption = CommandBars("Spelling").Controls(lngIndex).Caption
  48. .Style = msoButtonCaption
  49. .Tag = .Caption
  50. .OnAction = "CreateAutoCorrect"
  51. End With
  52. Next lngIndex
  53. 'Add the built-in AutoCorrect Options dialog
  54. Set oBtn = oPopUp.Controls.Add(msoControlButton, 793)
  55. lbl_Exit:
  56. ThisDocument.Saved = True
  57. Set oPopUp = Nothing
  58. Set oBtn = Nothing
  59. Exit Sub
  60. Err_Posit:
  61. lngPosit = lngPosit + 1
  62. Resume Err_Posit_Reentry
  63. End Sub
  64.  
  65. Sub RemoveContentMenuItem()
  66. CustomizationContext = ThisDocument.AttachedTemplate
  67. CommandBars("Spelling").Reset
  68. ThisDocument.Saved = True
  69. lbl_Exit:
  70. Exit Sub
  71. End Sub
  72.  
  73. Sub CreateAutoCorrect(Optional strWord As String)
  74. Dim cmdBCtl As CommandBarControl
  75. Dim oRng As Word.Range
  76. Dim arrChars() As String
  77. Dim lngLen As Long, lngIndex As Long
  78. Dim strAppend As String
  79. ReDim arrChars(0)
  80. Set cmdBCtl = Application.CommandBars.ActionControl
  81. Set oRng = Selection.Words(1)
  82. lngLen = Len(oRng)
  83. If lngLen <> Len(Trim(oRng)) Then
  84. ReDim arrChars(lngLen - Len(Trim(oRng)) - 1)
  85. For lngIndex = 0 To UBound(arrChars)
  86. arrChars(lngIndex) = Mid(oRng, Len(Trim(oRng)) + lngIndex + 1, 1)
  87. Next
  88. End If
  89. Application.AutoCorrect.Entries.Add Name:=Trim(oRng), Value:=cmdBCtl.Tag
  90. For lngIndex = 0 To UBound(arrChars)
  91. strAppend = strAppend & arrChars(lngIndex)
  92. Next lngIndex
  93. Selection.Words(1) = cmdBCtl.Tag & strAppend
  94. RemoveContentMenuItem
  95. lbl_Exit:
  96. Exit Sub
  97. End Sub
Add Comment
Please, Sign In to add comment