PDA

View Full Version : Word 2013 Spelling Context Menu/AutoCorrect command



gmaxey
07-31-2013, 08:51 PM
I've been noticing a few posts in other forums regarding MS decision to remove the AutoCorrect feature from the right click spelling context menu. Personally I don't think I've ever noticed it, but was intereste in seeing if it could be put back.

I've noticed in the past when MS removes a useful or useless feature from the UI, the underlying tool is stil available so I thought I could just customize the menu by adding the CommandBarPopup ID 30066 back to the spelling command bar. I was able to do that with no problem, but oddly the built-in popup does behave like the built-in popup in other Word versions. It is there, but it has no content. It doesn duplicate the list of suggested corrections list at the top of the spelling menu and it doesn't contain the built-in AutoCorrect options command buton. It is just an empy popup :-(

Not to be discourage I pressed on and I've managed cobble together a process that will replicate the process in earlier versons of Word, but at a cost in overhead that will likely make it useless. The only thing I could think to do was to manually add the list of suggested spellings in the AutoCorrect popup and manually add the AutoCorrect options button. I then created a macro to replicate (as best I could) Word native process for creating autocorrect entries form the popup. The nasty part is that the spelling command bare has to be reset and recreated with each selection change. That is the cost in overhead that makes the whole thing questionable.

I realize it is a lot of code, but if anyone looks at it and can see something I've done that prevents to built-in AutoCorrect popup from working like it seems it should then this might but a useful tool. Thanks.


Option Explicit
Public p_ThisApp As clsThisApp
Public Sub InitiateAppClass()
Set p_ThisApp = Nothing
Set p_ThisApp = New clsThisApp
lbl_Exit:
Exit Sub
End Sub
Sub BuildControls()
Dim oPopUp As CommandBarPopup
Dim oCtr As CommandBarControl
Dim oBtn As CommandBarButton
Dim lngIndex As Long
Dim lngMarker As Long

CustomizationContext = ThisDocument.AttachedTemplate
'Prevent double customization
Set oPopUp = CommandBars.FindControl(Tag:="BuiltInAC")
If Not oPopUp Is Nothing Then GoTo lbl_Exit
On Error GoTo lbl_Exit
'Determine where the "Ignore All" control is located. This tells us how many suggested spellings are in the context menu.
lngMarker = CommandBars("Spelling").Controls("&Ignore All").Index
'Add the built-in AutoCorrect popup
Set oPopUp = CommandBars("Spelling").Controls.Add(msoControlPopup, 30096, , CommandBars("Spelling").Controls("&Hyperlink...").Index, 1)
With oPopUp
.Tag = "BuiltInAC"
.BeginGroup = True
End With

'I would have thought that the built-in popup would include the suggested spelling and the AutoCorrect options dialo, but it doesn't.
'Yuck. This means that they will have to be fudged and added\removed with each selection change :-(
For lngIndex = 1 To lngMarker - 1
Set oBtn = oPopUp.Controls.Add(msoControlButton, CommandBars("Spelling").Controls(lngIndex).ID)
With oBtn
.Caption = CommandBars("Spelling").Controls(lngIndex).Caption
.Style = msoButtonCaption
.Tag = CommandBars("Spelling").Controls(lngIndex).Caption
.OnAction = "CreateAutoCorrect"
End With
Next lngIndex
'Add the built-in AutoCorrect Options dialog
Set oBtn = oPopUp.Controls.Add(msoControlButton, 793)
lbl_Exit:
Set oPopUp = Nothing
Set oBtn = Nothing
Exit Sub
End Sub
Sub RemoveContentMenuItem()
CustomizationContext = ThisDocument.AttachedTemplate
CommandBars("Spelling").Reset
lbl_Exit:
Exit Sub
End Sub
Sub CreateAutoCorrect(Optional strWord As String)
Dim cmdBCtl As CommandBarControl
Dim oRng As Word.Range
Dim arrChars() As String
Dim lngLen As Long, lngIndex As Long
Dim strAppend As String
Set cmdBCtl = Application.CommandBars.ActionControl
Set oRng = Selection.Words(1)
lngLen = Len(oRng)
If lngLen <> Len(Trim(oRng)) Then
ReDim arrChars(lngLen - Len(Trim(oRng)) - 1)
For lngIndex = 0 To UBound(arrChars)
arrChars(lngIndex) = Mid(oRng, Len(Trim(oRng)) + lngIndex + 1, 1)
Next
End If
Application.AutoCorrect.Entries.Add Name:=Trim(oRng), Value:=cmdBCtl.Tag
For lngIndex = 0 To UBound(arrChars)
strAppend = strAppend & arrChars(lngIndex)
Next lngIndex
Selection.Words(1) = cmdBCtl.Tag & strAppend
lbl_Exit:
Exit Sub
End Sub




Option Explicit
Private WithEvents m_oThisApp As Application
Private Sub Class_Initialize()
Set m_oThisApp = Word.Application
cls_Initialize_Reset
lbl_Exit:
Exit Sub
End Sub
Private Sub m_oThisApp_DocumentOpen(ByVal doc As Document)
cls_Initialize_Reset
lblbl_Exit:
Exit Sub
End Sub
Private Sub m_oThisApp_DocumentChange()
cls_Initialize_Reset
lbl_Exit:
Exit Sub
End Sub
Private Sub m_oThisApp_WindowSelectionChange(ByVal Sel As Selection)
cls_Initialize_Reset
lbl_Exit:
Exit Sub
End Sub
Private Sub cls_Initialize_Reset()
Dim lngCur As Long
On Error GoTo lbl_Exit
lngCur = System.Cursor
System.Cursor = wdCursorNormal
Module1.RemoveContentMenuItem
Module1.BuildControls
On Error GoTo 0
System.Cursor = lngCur
lbl_Exit:
Exit Sub
End Sub

gmaxey
08-04-2013, 12:20 PM
The above is now cross-posted at: http://social.msdn.microsoft.com/Forums/office/en-US/26dc0549-0974-4634-a8e8-c7ada5f776a6/commandbar-popup-behaviour-in-word2013. This highlights yet another reason why I wish you would change your edit policy and allows editing of posts at any time in the future. I shouldn't have to reply to my own post just to add information like this. Also reading the above with rested eyes, I see that if is rife with typos that will forever stand as testiment to my poor spelling practices ;-)