Possible to override ClearFormatting command?

J

J Whales

Hello!

I would like to override Word's 'Clear Formatting' command - basically
to apply a style other than 'Normal' once the formatting is cleared.

I tried creating a 'ClearFormatting()' sub but it doesn't get called (I
did one for FileSave in the same module and that one worked fine).

Is it possible? Or is there a way to configure the document to use a
style other than 'Normal' for the 'Clear Formatting' command?

Thanks

J Whales
 
C

Cindy M -WordMVP-

Hi J,
I would like to override Word's 'Clear Formatting' command - basically
to apply a style other than 'Normal' once the formatting is cleared.

I tried creating a 'ClearFormatting()' sub but it doesn't get called (I
did one for FileSave in the same module and that one worked fine).

Is it possible? Or is there a way to configure the document to use a
style other than 'Normal' for the 'Clear Formatting' command?
The problem is that using the commands in this Task Pane doesn't trigger
any of the internal Word commands. so, as far as I know, there is no way
to intercept this.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
K

Klaus Linke

Not sure whether that's a general problem of the task panes or just buggy
implementation:
Quite a few things you do on the task panes do trigger the corresponding
Word commands.

To find out whether something can be intercepted, you can use Alt+Shift+Num+
(ToolsCustomizeKeyboardShortcut) and choose some item on the task pane (or
on some item from a dropdown menu on the task pane).
If it can be intercepted, you get the "Customize keyboard shortcut" dialog
with the command's name.

Regards,
Klaus
 
C

Cindy M -WordMVP-

Hi Klaus,
Not sure whether that's a general problem of the task panes or just buggy
implementation:
Basically, it's because the taskpane commands don't run in the "normal" Word
executable. The commands are triggered by ActiveX controls (that's all the
stuff in the TaskPane) which execute "outside" Word.

Can you give me an example of a command in a to you can pick up using
Alt+Ctl+Num+?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
K

Klaus Linke

Hi Cindy,

Yes, I've compiled a list, but I have it at home and will post it tomorrow.
It isn't too much.

I haven't looked yet what of that stuff is covered in Steve Hudson's
article, too.

Regards,
Klaus
 
K

Klaus Linke

Steve Hudson has dealt with te new built-in commands relating to task panes
pretty extensively already:
http://word.mvps.org/faqs/macrosvba/TaskPanesReferenceContentBody.htm#New_Word_Commands

Below are a few macros I used to check intercepting stuff, anyway.

The "executive" version:
Of the work panes themselves, you can intercept everything except
-- "Help" and "Search Results"
-- "Clipart" (probably because of a misnomer)
-- "New document": very limited
(some panes, I haven't tested)

On the task panes themselves, only a couple of commands can be intercepted.
One is "ClearFormatting" which started this thread: It is intercepted when
you click on the right-side context menu > "Clear Formatting…" of the
"Formatting of selected text" (but, as discovered, not if you click on
"Clear Formatting" in the list below).

Other examples:
-- "Research" and "EditFind" at the bottom of the basic and advanced file
search panes,
-- "DocumentActionsPane" runs each time you create a new document or open an
existing one from the "New document" or "Getting started" pane (although
you'd use AutoNew/AutoOpen or document event macros for that).
-- "FormatStyleVisibility" = "Show styles > Custom..." at the bottom of the
styles and formatting pane
-- "Templates and Add-Ins…" on the "XML Structure" task pane (limited use,
since you can't mimic the built-in command in the intercepted macro?)

So it seems that actions that result in another dialog or showing another
task pane can be intercepted, at least in principle.

The only example where a command that results in an immediate action can be
intercepted (except the buggy "FileNew", which immediately creates a new
document instead of showing the "New document" task pane) is, ironically,
"ClearFormatting"!

You can copy the (commented) code below in a module to see the actions being
intercepted (just showing a message box and then performing the built-in
command).
The dialog constant and command ID are given, too... sometimes you might
need them for work-arounds when WordBasic won't do.

Regards,
Klaus



~~~~~~~~~~~~~~~~~~~~
' CommandBars.FindControl(ID:=###).Execute in a macro with the command's
name
' will never work: It calls the same command again and then errors.
' But elsewhere, it'll work fine and is sometimes helpful because it's the
surefire way
' to really run the command the same way as when you click the button.
' So if, say, dialogs become modal when using WordBasic, or something else
' works differently than in the UI, it's worth a try.

Sub ViewTaskPane()
' (Strg+F1)
MsgBox "ViewTaskPane"
' CommandBars.FindControl(Id:=5905).Execute
' Dialogs(1363).Show
WordBasic.ViewTaskPane
End Sub


Sub GettingStartedPane()
' Shows the Getting Started taskpane
MsgBox "GettingStartedPane"
' no wdTaskPane constant?
' CommandBars.FindControl(ID:=7397).Execute
' Dialogs(1468).Show ' works
WordBasic.GettingStartedPane
End Sub

Sub EditOfficeClipboard()
MsgBox "EditOfficeClipboard"
' CommandBars("Clipboard").Visible = True
' doesn't work any more in Word 2003
' also no wdTaskPane constant available
' CommandBars.FindControl(ID:=809).Execute
' Dialogs(459).Show ' works
WordBasic.EditOfficeClipboard
End Sub

' Can't intercept "Help" and "Search Results"?

' Clip Art task pane can't be intercepted either?
' See two macros below:

Sub DrawRunCag()
' Should display the "Clipart" task pane?
' does not work? Confusion with InsertDrawRunCag?
MsgBox "DrawRunCag"
WordBasic.DrawRunCag
End Sub

Sub InsertDrawRunCag()
' Should display the "Clipart" task pane?
' does not work? Confusion with DrawRunCag?
MsgBox "InsertDrawRunCag"
WordBasic.InsertDrawRunCag
End Sub

Sub Research()
MsgBox "Research"
' CommandBars.FindControl(ID:=7343).Execute
' Dialogs(1459).Show ' works
' Application.TaskPanes.Item(wdTaskPaneResearch).Visible _
' = True ' endless loop here
WordBasic.Research
End Sub

Sub FileNew()
MsgBox "FileNew" & vbCr & _
"(Can't bring up the ""New Document"" work pane)"
' What now?
' WordBasic immediately creates a new doc based on Normal:
' WordBasic.FileNew
' The Dialog shows the old-style dialog, not the task pane:
' Dialogs(wdDialogFileNew).Show
' The task pane has no wdTaskPane index
' Application.TaskPanes.Item(??).Visible = True
' CommandBars.FindControl(ID:=18).Execute ' results in loop here
' And SendKeys (yuck) seems to be out since the task pane
' doesn't seem accessible with the keyboard?
End Sub

Sub DocumentActionsPane()
' Smart Document task pane
' "New Document" task pane, Click on some item:
' The new document will be created, then your
' Sub DocumentActionsPane() will run.
' Seems to run whenever a new doc is opened or created?
MsgBox "DocumentActionsPane"
' Application.TaskPanes.Item(wdTaskPaneDocumentActions).Visible _
' = True ' doesn't work?
' WordBasic.DocumentActionsPane
' Command seems to run anyway?
End Sub

Sub DisplaySharedWorkspacePane()
' Display "Shared Workspace" task pane
' (but doesn't run if you click on "Shared Workspace"
' on the "Document Updates" task pane!)
MsgBox "DisplaySharedWorkspacePane"
WordBasic.DisplaySharedWorkspacePane
' Application.TaskPanes.Item(wdTaskPaneSharedWorkspace).Visible _
' = True ' endless loop here
' CommandBars.FindControl(ID:=7710).Execute
' Dialogs(1330).Show ' works
End Sub

Sub ShowSmPane()
' Displays the Document Updates Pane
MsgBox "ShowSmPane"
' CommandBars.FindControl(ID:=7423).Execute
' doesn't seem to work?
' Dialogs(1327).Show ' works
' Application.TaskPanes.Item(wdTaskPaneDocumentUpdates).Visible _
' = True 'endless loop?
' WordBasic.ShowSmPane
End Sub

Sub ToolsProtect()
' Display "Protect Document" task pane.
MsgBox "ToolsProtect"
' CommandBars.FindControl(ID:=7116).Execute
' Application.TaskPanes.Item(wdTaskPaneDocumentProtection).Visible _
' = True ' runs macro, then error
' Dialogs(1240).Show ' works
WordBasic.ToolsProtect
End Sub

Sub FormattingPane()
' Applies, creates, or modifies styles and formatting
' On the formatting pane:
' -- Clicking on the right-side context menu >
' "Reveal Formatting…" of the "Formatting of selected text"
' runs "FormattingProperties".
' -- Clicking on the right-side context menu >
' "Clear Formatting…" of the "Formatting of selected text"
' runs "ClearFormatting".
' -- Clicking on "Show: Custom" at the bottom of the pane
' runs "FormatStyleVisibility".
MsgBox "FormattingPane"
' Application.TaskPanes.Item(wdTaskPaneFormatting).Visible _
' = True ' endless loop here
WordBasic.FormattingPane ' works
' CommandBars.FindControl(ID:=5757).Execute
' Dialogs(1364).Show ' works
End Sub

Sub FormatStyleVisibility()
' Changes the visibility state of the document's styles
' Display Dialog "Formatting Settings", also
' by clicking on "Show: Custom" at the bottom
' of the "Styles and Formatting task pane.
MsgBox "FormatStyleVisibility"
' CommandBars.FindControl(ID:=6058).Execute
' Dialogs(wdDialogFormatStylesCustom).Show ' works
WordBasic.FormatStyleVisibility ' works
End Sub

Sub ClearFormatting()
MsgBox "ClearFormatting"
WordBasic.ClearFormatting
End Sub

Sub FormattingProperties()
' Display "Reveal formatting" task pane;
' also by clicking on the right-side context menu
' > "Reveal Formatting…" of the "Formatting of
' selected text" at the top of the "Styles and
' Formatting" task pane.
' BTW: The "hyperlinks" run the built-in commands
' (FormatFont, ToolsLanguage, …), and choosing
' "Show all formatting marks" at the bottom runs
' "ShowAll"!
MsgBox "FormattingProperties"
' Application.TaskPanes.Item(wdTaskPaneRevealFormatting).Visible _
' = True 'endless loop?
' CommandBars.FindControl(ID:=6094).Execute
' Dialogs(1062).Show ' works
WordBasic.FormattingProperties
End Sub

Sub MailMergeWizard()
MsgBox "MailMergeWizard"
' Application.TaskPanes.Item(wdTaskPaneMailMerge).Visible _
' = True ' Endless loop here
' CommandBars.FindControl(ID:=6070).Execute
' Dialogs(1246).Show ' works
WordBasic.MailMergeWizard
End Sub

Sub ViewXMLStructure()
' Display "XML Structure" task pane
MsgBox "ViewXMLStructure"
' CommandBars.FindControl(ID:=7171).Execute
' would work, but makes endless loop here
' Application.TaskPanes.Item(wdTaskPaneXMLStructure).Visible _
' = True ' runs macro, then error
' Dialogs(1388).Show ' works
WordBasic.ViewXMLStructure
End Sub

Sub FileTemplates()
' Changes the active template and the template options;
' Display "XML Schema" tab of the
' "Templates and AddIns" dialog
' (also if you click on "Templates and Add-Ins…"
' on the "XML Structure" task pane).
MsgBox "FileTemplates"
With Dialogs(wdDialogToolsTemplates)
' The built-in command seems to know which tab to show;
' we have to decide on a specific one:
.DefaultTab = wdDialogTemplatesXMLSchema
.Show
End With
' WordBasic.FileTemplates ' (doesn't seem to work)
End Sub

Sub EditFind()
MsgBox "EditFind"
WordBasic.EditFind
End Sub

Sub FileSearch()
' Brings up the Search UI workpane
' "Research" and "EditFind" ("Find in this document...") can be
intercepted
' both in the Basic and Advanced search pane
MsgBox "FileSearch"
' Dialogs(1363).Show
' CommandBars.FindControl(Id:=5905).Execute
WordBasic.EditFind
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top