Re: Cancel Printing Except Q
- From: Dave Peterson <petersod@xxxxxxxxxxxxxxxx>
- Date: Tue, 16 Jan 2007 14:51:20 -0600
My bet is the usernames that you put in that don't match what excel has for the
..username.
Maybe a few:
msgbox application.username
will help you see the differences.
Remember that the user can change this name pretty easily.
Tools|Options|general and a little typing and they can print (or mess it up so
that they can't print!).
Sean wrote:
Slight twist in the code. If a the user is listed in MyUser2 range name
then, print otherwise don't.
My Problem is that it's not printing regardless if the user is listed.
Anything wrong with the code?
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim myArray As Variant
Dim arName As String
arName = "MyUsers2"
myArray = ThisWorkbook.Names(arName).RefersToRange.Value
With Application
If IsError(.Application.Match(.UserName, myArray, 0)) Then
Cancel = True
Else
Cancel = False
End If
End With
End Sub
Dave Peterson wrote:
There are options to show different buttons on the msgbox. But I'm not sure
that's your question.
If it is, VBA's help will explain what you can use.
Sean wrote:
Thanks Dave.
How aboutthe attached code, I picked and tweaked from this NG, seems to
work okay. Can I chnage the type of Msg Box
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim sReply As String
sReply = Application.InputBox( _
Prompt:="Please enter the password", _
Title:="Password Required", _
Type:=2)
If sReply = "1234" Then
Cancel = False
'''Run the password protected code.
MsgBox " Click OK to commence Printing"
Else
Cancel = True
'''Do not run the password protected code.
MsgBox "Sorry, incorrect Password. You are not permitted to Print this
Document"
End If
End Sub
Dave Peterson wrote:
You could add some code to disable events (including the _beforeprint event) in
your code that gets/validates the password.
dim myPwd as string
'some validation here
if mypwd = "oktoprint" then
application.enableevents = false
worksheets("whatever").printout
application.enableevents = true
end if
And the _BeforePrint routine won't even run.
Sean wrote:
I have the following code which prevents priniting of a document. Would
it be possible to allow printing if the correct password was entered
within a userform? So on clicking the Print Icon an input box which
required the password would appear, if it is correct, document prints,
if it isn't document doesn't. If so how would I do it?
Thanks
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Cancel = True
End Sub
--
Dave Peterson
--
Dave Peterson
--
Dave Peterson
.
- Follow-Ups:
- Re: Cancel Printing Except Q
- From: Sean
- Re: Cancel Printing Except Q
- References:
- Cancel Printing Except Q
- From: Sean
- Re: Cancel Printing Except Q
- From: Dave Peterson
- Re: Cancel Printing Except Q
- From: Sean
- Re: Cancel Printing Except Q
- From: Dave Peterson
- Re: Cancel Printing Except Q
- From: Sean
- Cancel Printing Except Q
- Prev by Date: Re: Workbook.Open fail in 2003, good in XP
- Next by Date: Re: Workbook.Open fail in 2003, good in XP
- Previous by thread: Re: Cancel Printing Except Q
- Next by thread: Re: Cancel Printing Except Q
- Index(es):
Loading