VSTO 2005- Floating vs. Inline Controls in Word 2003 Printing

One of the requests that comes around every now and again is this: Can you make it so that when a user prints a doc from Word, embedded controls don't print?

The answer is "Yes"....IF the controls are floating rather than inline. For example, if you right click on a button embedded in a document, select Format Control. On the Layout tab you will see five different choices for how the control behaves in Word with respect to document text. Making the button appear inline with the text means that it will be an InlineShape when you access its properties programmatically. If you elect to have it in front of the text, it will be a floating control that y ou can move around without much worry about the text. You can cover text and so forth. When you access the control programmatically, it will ba  Shape, not an InlineShape.

This distinction is vital because InlineShapes cannot be hidden. But, you can hide Shapes. NOTE: This is the case with Word 2003. Earlier versions behaved somewhat differently. Here's some VBA to loop through Shapes and make them invisible:

Sub ShapesCheck()
Dim myShape As Shape
With ActiveDocument
For Each myShape In .Shapes
myShape.Visible = msoFalse
Next myShape
End With
End Sub

Note: there is the Tools | Options | Print tab that has an option for not printing drawing objects. But, this does not work with InlineShapes either, and the VBA code will give the capability to have a consistent experience with earlier Word versions not offering this dialog option.

Here's code to loop through InlineShapes and attempt to make them not visible:

Sub InlineShapesCheck()
Dim myShape As Word.InlineShape
Dim btn As MSForms.CommandButton
With ActiveDocument
For Each myShape In .InlineShapes
If myShape.Type = wdInlineShapeOLEControlObject Then
If myShape.OLEFormat.ClassType Like _
"Forms.CommandButton*" Then
Set btn = myShape.OLEFormat.Object
'Cannot do this because
'InlineShape lacks this property.
'btn.Enabled = False
End If
End If
Next myShape
End With
End Sub

Now, what does this have to do with printing? Well, if you have embedded controls that you do not want to appear when printing, you can only toggle the visibility of Shapes. How do you hide the Shapes before Word prints? It's pretty easy:

1) Create a VBA macro called FilePrint

2) Put your custom code in there to hide buttons etc.

FilePrint is a Word command, so creating a macro with this name lets you override the default behavior.

Later today, I'll tie this printing issue to VSTO 2005 and its controls.

Rock Thought for the Day: Have you ever sat down at the piano or with your guitar and just played- not a song or a linear composition- just played whatever came to you? What if you gave it just enough structure and purpose and turned it into an album? That would be YOB's new record The Unreal Never Lived. As I constantly emphasize, life is not all pain and doom. There are often moments of great joy and satisfaction. But music about that doesn't move as many units as some old-fashioned despondency put to song! YOB have an album that, yes, disenfranchised youths will listen to repeatedly in rooms with Tony Hawk posters barely visible at noon in July. But, it is a musician's music as well. Careful listening reveals plenty of thought, planning, and smart note choices. Just keep "Tie a yellow ribbon" by Tony Orlando handy as the anti-dote to YOB's somber dissonance.

Rock On