Hide Command Button when Printing

G

Gail

I have a command button that dletes extra rows in a Word table. When the user
prints the table, I do not want the command button to show. I have tried code
from "how to hide a "Print" button when user clicks on it" in MVP - the
problem is - I do not want to print the document immediatly. I just want the
button hidden when the user choses to print the document. I also tried to
interecpt the Print command and then hide - but it prints 2 copies - one
hidden and one with the button showing. Here is the code I am using to
intercept:

Dialogs(wdDialogFilePrint).Show

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

Helmut Weber

Hi Gail,
Here is the code I am using to intercept:

Dialogs(wdDialogFilePrint).Show

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

which doesn't intercept fileprint a all.

I tried this and that and can only offer
a silly workaround, as
shapes(1).visible = msofalse
doesn't do anything.

Sub FilePrint()
' ActiveDocument.Shapes(1).Visible = msoFalse ?
ActiveDocument.Shapes(1).Delete
' on error resume next
Dialogs(wdDialogFilePrint).Show
' ActiveDocument.Shapes(1).Visible = msoTrue ?
ActiveDocument.Undo 1
End Sub

Note, this assumes, that there is a shape(1)!
But shouldn't be too difficult,
to add a bit more of error handling.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
G

Gail

Helmut

This macro works great - is there a way to make the command button/shape
reappear after printing as well? Thank you!!
 
H

Helmut Weber

Hi,

as deleting it was the last editing action
undo 1
undoes deleting it here and now.

there maybe unwanted sideeffects as with
all workarounds.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

Helmut Weber
 

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