Whilst we wait for The Word guru's to float by, maybe something like this:
Sub CreateSmartQuotesToggleButton()
' Get the Ribbon object
Dim objRibbon As IRibbonUI
' Check if the custom tab already exists. If so, exit.
' This prevents adding the tab multiple times.
On Error Resume Next
' Handle potential error if tab doesn't exist
Application.CommandBars("Ribbon").FindControl(ID:="SmartQuotesTab")
If Err.Number = 0 Then
' Tab already exists On Error GoTo 0
' Reset error handling
Exit Sub
End If
On Error GoTo 0
' Reset error handling
' Create the custom Ribbon tab
Set objRibbon = Application.CommandBars("Ribbon")
With objRibbon.Controls.Add(Type:=msoControlCustom, ID:="SmartQuotesTab")
.Caption = "Smart Quotes"
' Tab caption .Visible = True
' Create the toggle button within the tab
With .Controls.Add(Type:=msoControlToggleButton, ID:="SmartQuotesToggle")
' Button caption .
.Caption = "Smart Quotes"
' Tooltip
.Description = "Toggle Smart Quotes on/off"
' Procedure to execute on click
.OnAction = "ToggleSmartQuotes"
' Procedure to get the button's pressed
.OnGetPressed = "GetSmartQuotesToggleState"
' Procedure to get the button's pressed state
.ImageMso = "Symbol"
' Choose an appropriate icon (or create a custom one) - "Symbol" is a placeholder. Look up msoImageMso values for options.
.Visible = True
End With
End With
' Invalidate the Ribbon to reflect changes
objRibbon.Invalidate
' Initialize the Smart Quotes state and the button state
bSmartQuotesEnabled = Application.AutoCorrect.AutoFormatAsYouTypeReplaceQuotes
' Update the button state
objRibbon.InvalidateControl "SmartQuotesToggle"
End Sub
' Callback procedure for the toggle button's OnAction event
Sub ToggleSmartQuotes(control As IRibbonControl, pressed As Boolean)
' Update global variable
bSmartQuotesEnabled = pressed
Application.AutoCorrect.AutoFormatAsYouTypeReplaceQuotes = pressed Application.AutoCorrect.AutoFormatReplaceQuotes = pressed
' Important: Set both!
' Optionally, provide visual feedback (e.g., a message box or status bar update)
' MsgBox "Smart Quotes are now " & IIf(pressed, "On", "Off") <=== ' Remove Rem if required
' Invalidate the control to update the button's appearance if needed.
' In most cases this will not be necessary.
' Application.CommandBars("Ribbon").InvalidateControl "SmartQuotesToggle"
End Sub
' Callback procedure for the toggle button's OnGetPressed event
Sub GetSmartQuotesToggleState(control As IRibbonControl, pressed As Boolean)
' Set the button's pressed state based on the global variable
pressed = bSmartQuotesEnabled
End Sub
' Procedure to run when the document opens (or when the add-in is loaded)
Sub AutoOpen()
' Create the button if it doesn't exist
CreateSmartQuotesToggleButton
End Sub
' Procedure to run when the add-in is loaded
Sub AddInInitialize()
' Create the button if it doesn't exist
CreateSmartQuotesToggleButton
End Sub