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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to prevent users from printing in word? 1

Status
Not open for further replies.

StuckInTheMiddle

Programmer
Mar 3, 2002
269
US
I need to prevent my users from Printing when using word.

I can prevent them from doing so from the File->Print menu, but I can not seem to override the 'Print' button on the word toolbar (Hiding the toolbar is not an option).

An example of overriding the FilePrint is to create the following sub in a word module.


Sub FilePrint()

MsgBox "Not Allowed, sorry."

End Sub
[/color blue]

The Macro Recorder tells me that the 'Print' button on the toolbar calls ActiveDocument.PrintOut except trying to override this as


Sub PrintOut()

MsgBox "Not Allowed, sorry."

End Sub
[/color blue]

or

sub ActiveDocumentPrintOut[/color blue] or numerous other combinations has failed to work. I can't seem to find the Printout command listed in the built-in 'Word Commands' (under Tools>Macros>Macros in 'Word Commands'

Any help appreciated,

Thanks







(The more ASP.NET I do, the more Javascript I find myself using)
 
Just for the record, even if you manage to do that they can still print using Print screen or using any of the Print utilities such as Snagit. Snagit for example will autoscroll the activewindow and then grab the whole lot and either save it as an image or put it on the clipboard where it could easily be pasted into excel for example.

Regards
Ken..................

----------------------------------------------------------------------------
[peace]It's easier to beg forgiveness than ask permission[2thumbsup]
---------------- Click here to help the tsunami victims ----------------

 
Ken: Know pretty much nothing about VBA for Word, but is there not some kind of inactivate event like in Excel?

(This of course ignoring your very correct statement that Snagit or print screen will do the job anyway)

// Patrik
______________________________

To the optimist, the glass is half full. To the pessimist, the glass is half empty. To the IT Professional, the glass is twice as big as it needs to be.
 
Hmm... found what i was looking for:

Create a new class module. Name it EventClassModule (for example)

Insert this code:

Code:
Public WithEvents App As Word.Application

Private Sub app_DocumentBeforePrint(ByVal Doc As Document, Cancel As Boolean)

    MsgBox ("The owner of this document has disallowed the possibility to print the document.")
    Cancel = True
    
End Sub

Create a normal module, paste the following code:

Code:
Dim X As New EventClassModule
Sub Register_Event_Handler()
    Set X.App = Word.Application
End Sub

Run that code (connects the "App" with the "word.application" in the class module)


Bingo - now you have disallowed printing!

// Patrik
______________________________

To the optimist, the glass is half full. To the pessimist, the glass is half empty. To the IT Professional, the glass is twice as big as it needs to be.
 
First thing I'd do when I opened the document is disable macros :) Then print normally.

Depends if you're just trying to stop casual printing, only someone determined will get there in the end. If you can see it you can usually print it.

Regards
Ken................

----------------------------------------------------------------------------
[peace]It's easier to beg forgiveness than ask permission[2thumbsup]
---------------- Click here to help the tsunami victims ----------------

 
Of course, I agree - but the question is answered - this is the way you structure the code to disable printing.

When it comes to avoid disabling macros, there is an easy solution in Excel, but not in Word: Set all sheets but one as visible = xlveryhidden in a workbook_beforeclose event, and visible = true in a workbook_open event; then protect the code with a pw.

The one sheet that's visible urges people to activate macros...

Unfortunately there's no such function in Word, to the best of my knowledge...

// Patrik
______________________________

To the optimist, the glass is half full. To the pessimist, the glass is half empty. To the IT Professional, the glass is twice as big as it needs to be.
 
To summarise: It's possible, but meaningless, to prevent printing in Word by using VBA.


In excel you can also simply use the built-in workbook_beforeprint event...

So, if you want to prevent people from priting the document, Excel is a better tool - but far from the best, since print screen and Snagit etc can "steal" the info anyway.



// Patrik
______________________________

To the optimist, the glass is half full. To the pessimist, the glass is half empty. To the IT Professional, the glass is twice as big as it needs to be.
 
KenWright,

You posted:
Just for the record, even if you manage to do that they can still print using Print screen or using any of the Print utilities such as Snagit. Snagit for example will autoscroll the activewindow and then grab the whole lot and either save it as an image or put it on the clipboard where it could easily be pasted into excel for example.

Will that program also grab the text from adobe documents that are prevented from printing ? This is a concern of mine, as I have copywriten text in an adobe document that is password protected from printing and copying. I've tried it as well myself to even select text, and it will not, but this program could pose a problem if that is the case.

Please let me know.
Thanks,
-SWarrior

 
Guys,

Thanks for all the comments. I have discovered that what I needed was to use 'FilePrintDefault' not 'FilePrint' to catch the user hitting the Print button in the word toolbar.


Sub FilePrintDefault()

MsgBox "Not Allowed, sorry."

End Sub


Also for your information, I am clearing the clipboard whenever Word loses focus to prevent users from copy/pasting data and this also this seems to work well with screen prints too, unless they take a screenprint when word doesnt have focus ;(. So I know that a determined user would be able to work around these measures but the idea is to simply deter the casual user from doing so.

Thanks again.


(The more ASP.NET I do, the more Javascript I find myself using)
 
A thought: if you can't prevent printing, can you misdirect the output? Perhaps to a printer the employee does not have access to, or to a file...
 
SWarrior - No idea to be honest, and I have just gotten a new version of snagit to play with as well, so if you wanted to dummy up a test sheet and post a link to it I'll happily give it a go.

Regards
Ken................

----------------------------------------------------------------------------
[peace]It's easier to beg forgiveness than ask permission[2thumbsup]
---------------- Click here to help the tsunami victims ----------------

 
Stuck in the middle:

Are you aware that your sub only inactivates the toolbar button, not the print out itself?

Try printing by ctrl+p or ctrl+shift+F12, as well as the menu option, and your protection is bypassed.

So if you want to disallow it, better use the code I posted.

// Patrik
______________________________

To the optimist, the glass is half full. To the pessimist, the glass is half empty. To the IT Professional, the glass is twice as big as it needs to be.
 

Thanks for your concern Patrik.

I was unaware of the ctrl+shift+F12 combination, but the 2 overrides I have used, as shown below, catch all the cases you mention, thanks.

Sub FilePrint()

MsgBox "Not Allowed, sorry."

End Sub

Sub FilePrintDefault()

MsgBox "Not Allowed, sorry."

End Sub
[/color blue]
I also have setup the following to prevent uses from printing through PrintPreview in word.

Public Sub FilePrintPreview()

MsgBox "Not Allowed, sorry."

End Sub
[/color blue]


(The more ASP.NET I do, the more Javascript I find myself using)
 

Another easy way round this kind of restriction is to select Print from the right click context menu on the document icon in (Windows) Explorer.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at [url=http://www.vbaexpress.
 
Tony: That can be sidestepped as well, in the folder options | File types tab | select .doc - advanced button - remove print...




// Patrik
______________________________

To the optimist, the glass is half full. To the pessimist, the glass is half empty. To the IT Professional, the glass is twice as big as it needs to be.
 
The ability to disable printing of a document is built into Word 2003 as part of the IRM features.
 
Yesm but that only works if you are using SharePoint Services.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top