PDA

View Full Version : Intercept Word Command



fionabolt
02-16-2010, 04:10 AM
In Word 2003, does anyone know a way to intercept the Word Command "Clear Formatting" when triggered from the "Styles and Formatting" task pane?

I have written the following code

Sub ClearFormatting()
'
' ClearFormatting Macro
'
MsgBox "Here in ClearFormatting"
Selection.ClearFormatting
Selection.Style = ActiveDocument.Styles("SOME STYLE OTHER THAN NORMAL")

End Sub


This works, but only when "ClearFormatting" is triggered from the "Style" box on the "Formatting" toolbar. However, when you select "Clear Formatting" from the task pane, the VBA code does not intercept it, and the Word default behaviour occurs, i.e. the style "Normal" is applied.

Has anyone found a solution to this anomaly.

Thanks
Fiona

fumei
02-16-2010, 09:58 AM
Sorry, no can do. This is one of the oddities (perhaps you can consider it a bug) of overwriting a Word command. You are correct. You can overwrite Clear Formatting via the Styles dropdown, but can NOT via the Styles and Formatting Task pane.

I am not sure why, but this is indeed the case. Choosing Clear Formatting from the Task pane executes the default instructions, regardless of any explicit Sub ClearFormatting().

"Has anyone found a solution to this anomaly."

Nope.