PDA

View Full Version : Solved: Hiding Command Buttons on Document



jasoncw
07-30-2007, 09:00 AM
I have a general question on command buttons. I do not want them to print. However, I do not see that they a "print object" format property as do the Excel command buttons, or a visible or hidden property. What is the proper way to hide these buttons on the document for printing purposes? I am currently just setting the height and width to 0, but it leaves a dot for each object on the printed document.

Code to intercept print events (Office 97):
Sub FilePrint()
'
' FilePrint Macro
' Prints the active document
'
If ThisDocument.ProtectionType = wdAllowOnlyFormFields Then _
ThisDocument.Unprotect
Call HideCommandButtons
Dialogs(wdDialogFilePrint).Show

Call UnhideCommandButtons
ThisDocument.Protect wdAllowOnlyFormFields, True
End Sub

Sub FilePrintDefault()
'
' FilePrintDefault Macro
' Prints the active document using the current defaults
'
If ThisDocument.ProtectionType = wdAllowOnlyFormFields Then _
ThisDocument.Unprotect
Call HideCommandButtons

ThisDocument.PrintOut

Call UnhideCommandButtons
ThisDocument.Protect wdAllowOnlyFormFields, True
End Sub
Code used to hide and unhide command buttons:
Sub HideCommandButtons()
'hides command buttons for printing
With ThisDocument.cmdCustomize
.Height = 0
.Width = 0
End With

With ThisDocument.cmdLetterhead
.Height = 0
.Width = 0
End With
End Sub

Sub UnhideCommandButtons()
'unhides command buttons
With ThisDocument.cmdCustomize
.Height = 23
.Width = 107
End With

With ThisDocument.cmdLetterhead
.Height = 23
.Width = 84.75
End With
End Sub
TIA

Jason

fumei
07-30-2007, 11:41 AM
I assume you are talking about AtiveX commandbuttons - from the Controls toolbar.

These are InlineShapes. They are therefore part of the document layer, just like text. Yes, you can shrink them to wee points, but as you note...they ARE still points. They do not have a Visible property.

In other words, they take up (however small) space in the document layer, and will in fact print.

That being said, yes, there is a way. How well it works depends on your placement of the controls.

If they are sitting by themselves, essentially in/on a single paragraph, then making that paragraph font Hidden works. Of course you DO have to uncheck Hidden text in the Include with document section of Print > Options.

If you do, then the control is still visible, and clickable, in the document, but it will not print.

Demo attached. Print it out. The first commandbutton will NOT be printed, as the paragraph it sits on is Hidden font. The second button WILL print, as the font is not Hidden.

Both buttons can still be used.

jasoncw
07-30-2007, 12:16 PM
Ah, thanks again for the tip, Gerry. :)

Jason

jasoncw
07-31-2007, 11:43 AM
I was researching another issue, and found another alternative solution to hiding the command buttons. They can be inserted into a text box, then the text box properties can be set to Visible = msoFalse before printing. Of course, this will also require intercepting the FilePrint and FilePrintDefault events.

http://word.mvps.org/FAQs/TblsFldsFms/HidePrintButton.htm

jasoncw
11-27-2007, 01:59 PM
Bringing back an old thread.

Gerry, now that I figured out how to achieve what you were explaining, I really appreciate it. Thanks again for your help.

Jason

lucas
11-27-2007, 08:43 PM
I never understood why you would put command buttons on the actual sheet.....I do it sometimes for testing a macro but delete the button when I have it working and set up a menu item....click here (http://slucas.virtualave.net/Wink/CustomMenuItem.htm) to see how.

jasoncw
11-30-2007, 09:25 AM
Hi, Lucas.

I agree that a menu item would be better. However, this is a template to be used by many users, many of which would not know to look at a custom menu. A command button is more user-friendly in my opinion.

Jason

TonyJollans
11-30-2007, 10:27 AM
This is interesting. Part of Microsoft's stated reason for the Ribbon is that toolbars - for various reasons - were not effective and often confused users if they were left dotted around the screen. You would seem to be confirming that. My personal opinion is that command buttons in documents are usually out of place. It remains to be seen whether the ribbon obviates the perceived requirement for them.

fumei
12-03-2007, 09:50 AM
I am with Tony on this. While I do - not often - put command buttons IN documents, I frankly don't like them. But then...like everything...sometimes there is a place for things.

Me? I like buttons on toolbars, or keyboard shortcuts. I myself - if it is something for ME, tend to make things fire by keyboard shortcuts. I dislike having to reach over to the mouse if I don't have to.

I have never understood - even after I have shown people - this thing about:

type type type (in some sort of dialog, or box)....then lift their hand up from the keyboard, reach over to the mouse, move the mouse, and click OK. Ummmmm, people, in most cases you can:

type, type type...and with your hands still on the keyboard...ummm, press Enter.

I don't get it, but I would say most people in fact do in fact stop, reach for the mouse, move it to OK, and click it. They have this perception that they MUST click OK.

Shrug.