Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How prevent printing embeded command button in Word

Status
Not open for further replies.

johnatpm

Technical User
Mar 19, 2009
4
US
I have a MS Word doc file that I have placed/embedded a command button that prints that page. When I press the button, the page is printed, but it also prints that button.

I was wondering if there was a way to prevent the button from printing?

I realize that I could have the button on the toolbar, but I would rather have it on the page.

I went into the VB editor and looked at the properties of the button and didn't see any type of reference (true/false) that would keep it from being printed.
 
Thanks for the reply.

I tried to apply the code in several different ways to make it work with what I'm trying to do, but I can't seem to get it to work. I keep getting various errors.

Although my document will have several pages, I'm trying to get it to only print out the first page without the command button.

Here's the original recorded macro that I was trying to merge my code with your suggested code:

Private Sub CommandButton1_Click()

Application.PrintOut FileName:="", Range:=wdPrintRangeOfPages, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="1", PageType:=wdPrintAllPages, _
ManualDuplexPrint:=False, Collate:=True, Background:=True, PrintToFile:= _
False, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0

End Sub


Here's your code suggestion:

Private Sub CommandButton1_Click()

With ActiveDocument
.Shapes(1).Visible = msoFalse
.PrintOut Background:=False
.Shapes(1).Visible = msoTrue
End With

End Sub

 
What about this ?
Code:
Private Sub CommandButton1_Click() 
With ActiveDocument 
    .Shapes(1).Visible = msoFalse 
    .PrintOut Pages:="1", Background:=False 
    .Shapes(1).Visible = msoTrue 
End With 
End Sub

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I tried it and I got an error message that pops-up and says:

Run-time error '-2147024809 (80070057)':
The index into the specified collection is out of bounds.


When I click DEBUG in the error box, the VB editor highlights the line:

.Shapes(1).Visible = msoFalse
 
Did you cut'n'paste your command button in a TextBox ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Why not just has a wee macro that prints the current page and assign it a shortcut key? Much faster than having to click a button on the page. AND...it would apply to any page. So no need to even have a button.

Gerry
 
fumei,

I hear you, and I do appreciate any suggestions in case I hadn't thought about it. I do have some things in other documents in the way that you described, but for what I needed and wanted at my work place, I wanted it within the page. This way anyone that opened that particular document would see the button and click that to print the first page only.


PHV,

I finally got it to work. For some reason, it will only work if I create it as a .dot file and then save it as a .doc file. For some reason, Excel seems to be much more simpler to do things with macros than trying to do something like this in Word.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top