G
Greg Maxey
While I can't say that I am thrilled by the steps taken to get here, I think
I have figured out a way to at least simulate intercepting Word's "Print"
command in Word 2010.
I have a couple of Word 2003 and Word 2007 templates where in the interest
of being "Green," I have inserted code in templates that intercepted a users
attempt to print the documents if the left or right margin was greater than
1 inch.
This process was pretty straight forward in Word 2003 where I simply used
macros named "FilePrint" and "FileDefaultPrint" to intercept the user
actions and test for proper margins.
In Word2007, I repurposed the "FilePrint" and "FileQuickPrint" ribbon
controls and used a VBA callback to test for proper margins.
Concern started to rise when I saw a message from Jay Freeman a few monts
ago concerning the new interface in Word 2010:
"The FilePrint command, built-in or macro, seems to be obsolete. I haven't
found any way to intercept the Print button in the Print and
Preview screen. Although using the Ctrl+Alt+NumPadPlus shortcut (the
ToolsCustomizeKeyboardShortcut command) appears to show the Print
button calling the FilePrint command, a macro named FilePrint won't
intercept the button click."
I installed Word2010 a week or so ago and have confirmed Jay's observations.
Like Jay, I was also unable to find a way to intercept the Print button that
is located on the File>Print Tab.
From what I have been able to determine so far, this "Print" button is a
built-in control that is part a "GroupPrintSetting" built-in group, that is
part of a "PrintTab" built-in tab, that is part of the new Backstage UI.
I still have a lot to learn about all these new things, but what I have
learned so far is very disappointing.
First, it appears that none of the built-in controls of the Backstage UI can
be repurposed. This is FAQ published by Microsoft::
"Can I repurpose one of the existing definitive command buttons, fast
command buttons, or tabs by changing its onAction callback attribute? For
example can I change the file Save button so that is has an additional type,
or displays only one file type?
It is not possible to override these commands from the custom UI XML markup
or by using the object model. Using the DocumentBeforeSave event is one
alternative, but using that doesn't really change the functionality of the
individual commands that show up in the Change File Type gallery in the
Backstage. A better solution would be to consider hiding the built-in UI and
rebuilding it fully with custom commands."
Secondly, unlike built-in ribbon controls, it doesn't appear that you can
add built-in Backstage controls to new custom tabs or groups.
Next, again unlike built-in ribbon controls, the backstage controls don't
appear to be dynamic i.e., you can't set attributes like "getVisible" using
VBA callbacks.
Like the FAQ suggests, about all you can do is hide the built in controls
and then attempt to cobble together custom controls to meet your needs.
This is what I did here.
1. I wrote a XML script that:
a. repurposes the "FilePrintQuick" control that you can still add to
the ribbon or QAT.
b. hides the backstage "PrintTab" "GroupPrintSettings" control
c. Added a new "PRINT" and "QUICK PRINT" custom control to the "Print
Tab"
<?xml version="1.0" encoding="utf-8" ?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
<commands>
<command idMso="FilePrintQuick" onAction="BackStage.RepurposedQuickPrint"/>
</commands>
<backstage>
<tab idMso="TabPrint" >
<firstColumn >
<primaryItem>
<button id="custPrint" label="PRINT" imageMso="PrintAreaMenu"
isDefinitive="true" onAction="BackStage.OnAction" screentip="Select a
printer, number of copies, and other printer options before printing." />
</primaryItem>
</group>
<group id="customQuikPrinter" label="Quick Print">
<primaryItem>
<button id="custQuickPrint" label="QUICK PRINT" imageMso="FilePrintQuick"
isDefinitive="true" onAction="BackStage.OnAction" screentip="Send the
document directly to the default printer without making changes." />
</primaryItem>
</group>
</firstColumn>
</tab>
</backstage>
</customUI>
In the template, I added a module "Backstage" containing the following VBA
callbacks:
Option Explicit
Sub OnAction(control As IRibbonControl)
Select Case True
Case ActiveDocument.PageSetup.RightMargin > 72
MsgBox "Set green document margins and try again."
Case ActiveDocument.PageSetup.LeftMargin > 72
MsgBox "Set green document margins and try again."
Case Else
Select Case control.ID
Case "custPrint"
Application.Dialogs(wdDialogFilePrint).Show
Case "custQuickPrint"
CommandBars.ExecuteMso ("FilePrintQuick")
End Select
End Select
End Sub
Private Sub RepurposedQuickPrint(ByVal control As IRibbonControl, ByRef
cancelDefault)
cancelDefault = True
Select Case True
Case ActiveDocument.PageSetup.RightMargin > 72
MsgBox "Set green document margins and try again."
Case ActiveDocument.PageSetup.LeftMargin > 72
MsgBox "Set green document margins and try again."
Case Else
cancelDefault = False
End Select
End Sub
I realize this process seems and is clunky. I would certainly be nice if it
were possilbe to simple hide the "PRINT" button on the "PrintGroupSettings"
controls and add a custom button in its place, but unless I am missing
something that isn't possible.
Open to any comments or suggestions for improving this process.
--
Greg Maxey
See my web site http://gregmaxey.mvps.org
for an eclectic collection of Word Tips.
Arrogance is a weed that grows mostly on a dunghill (Arabic proverb)
I have figured out a way to at least simulate intercepting Word's "Print"
command in Word 2010.
I have a couple of Word 2003 and Word 2007 templates where in the interest
of being "Green," I have inserted code in templates that intercepted a users
attempt to print the documents if the left or right margin was greater than
1 inch.
This process was pretty straight forward in Word 2003 where I simply used
macros named "FilePrint" and "FileDefaultPrint" to intercept the user
actions and test for proper margins.
In Word2007, I repurposed the "FilePrint" and "FileQuickPrint" ribbon
controls and used a VBA callback to test for proper margins.
Concern started to rise when I saw a message from Jay Freeman a few monts
ago concerning the new interface in Word 2010:
"The FilePrint command, built-in or macro, seems to be obsolete. I haven't
found any way to intercept the Print button in the Print and
Preview screen. Although using the Ctrl+Alt+NumPadPlus shortcut (the
ToolsCustomizeKeyboardShortcut command) appears to show the Print
button calling the FilePrint command, a macro named FilePrint won't
intercept the button click."
I installed Word2010 a week or so ago and have confirmed Jay's observations.
Like Jay, I was also unable to find a way to intercept the Print button that
is located on the File>Print Tab.
From what I have been able to determine so far, this "Print" button is a
built-in control that is part a "GroupPrintSetting" built-in group, that is
part of a "PrintTab" built-in tab, that is part of the new Backstage UI.
I still have a lot to learn about all these new things, but what I have
learned so far is very disappointing.
First, it appears that none of the built-in controls of the Backstage UI can
be repurposed. This is FAQ published by Microsoft::
"Can I repurpose one of the existing definitive command buttons, fast
command buttons, or tabs by changing its onAction callback attribute? For
example can I change the file Save button so that is has an additional type,
or displays only one file type?
It is not possible to override these commands from the custom UI XML markup
or by using the object model. Using the DocumentBeforeSave event is one
alternative, but using that doesn't really change the functionality of the
individual commands that show up in the Change File Type gallery in the
Backstage. A better solution would be to consider hiding the built-in UI and
rebuilding it fully with custom commands."
Secondly, unlike built-in ribbon controls, it doesn't appear that you can
add built-in Backstage controls to new custom tabs or groups.
Next, again unlike built-in ribbon controls, the backstage controls don't
appear to be dynamic i.e., you can't set attributes like "getVisible" using
VBA callbacks.
Like the FAQ suggests, about all you can do is hide the built in controls
and then attempt to cobble together custom controls to meet your needs.
This is what I did here.
1. I wrote a XML script that:
a. repurposes the "FilePrintQuick" control that you can still add to
the ribbon or QAT.
b. hides the backstage "PrintTab" "GroupPrintSettings" control
c. Added a new "PRINT" and "QUICK PRINT" custom control to the "Print
Tab"
<?xml version="1.0" encoding="utf-8" ?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
<commands>
<command idMso="FilePrintQuick" onAction="BackStage.RepurposedQuickPrint"/>
</commands>
<backstage>
<tab idMso="TabPrint" >
<firstColumn >
<primaryItem>
<button id="custPrint" label="PRINT" imageMso="PrintAreaMenu"
isDefinitive="true" onAction="BackStage.OnAction" screentip="Select a
printer, number of copies, and other printer options before printing." />
</primaryItem>
</group>
<group id="customQuikPrinter" label="Quick Print">
<primaryItem>
<button id="custQuickPrint" label="QUICK PRINT" imageMso="FilePrintQuick"
isDefinitive="true" onAction="BackStage.OnAction" screentip="Send the
document directly to the default printer without making changes." />
</primaryItem>
</group>
</firstColumn>
</tab>
</backstage>
</customUI>
In the template, I added a module "Backstage" containing the following VBA
callbacks:
Option Explicit
Sub OnAction(control As IRibbonControl)
Select Case True
Case ActiveDocument.PageSetup.RightMargin > 72
MsgBox "Set green document margins and try again."
Case ActiveDocument.PageSetup.LeftMargin > 72
MsgBox "Set green document margins and try again."
Case Else
Select Case control.ID
Case "custPrint"
Application.Dialogs(wdDialogFilePrint).Show
Case "custQuickPrint"
CommandBars.ExecuteMso ("FilePrintQuick")
End Select
End Select
End Sub
Private Sub RepurposedQuickPrint(ByVal control As IRibbonControl, ByRef
cancelDefault)
cancelDefault = True
Select Case True
Case ActiveDocument.PageSetup.RightMargin > 72
MsgBox "Set green document margins and try again."
Case ActiveDocument.PageSetup.LeftMargin > 72
MsgBox "Set green document margins and try again."
Case Else
cancelDefault = False
End Select
End Sub
I realize this process seems and is clunky. I would certainly be nice if it
were possilbe to simple hide the "PRINT" button on the "PrintGroupSettings"
controls and add a custom button in its place, but unless I am missing
something that isn't possible.
Open to any comments or suggestions for improving this process.
--
Greg Maxey
See my web site http://gregmaxey.mvps.org
for an eclectic collection of Word Tips.
Arrogance is a weed that grows mostly on a dunghill (Arabic proverb)