View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default VBA Project - Second opinion please!

There is still no good way to have a macro unprotect that project (and reprotect
it).

Maybe you could write your code differently so that if the user answers with the
correct password (once in that session), then they aren't prompted again.

Option Explicit
Dim OkToPrint As Boolean 'initial value of false
Dim pCtr As Long 'initial value of 0
Private Sub Workbook_BeforePrint(Cancel As Boolean)

Dim myPWD As String
Dim UserPWD As String

myPWD = "hi"

If pCtr 30 Then
OkToPrint = False
Else
If OkToPrint = True Then
'don't ask again
Else
'ask
UserPWD = InputBox(Prompt:="Enter the password")
OkToPrint = CBool(UserPWD = myPWD)
End If
End If

If OkToPrint Then
'add one to the print counter
pCtr = pCtr + 1
Else
Cancel = True
MsgBox "Too many prints or not correct password"
End If

End Sub

Remember that print preview will count toward the total, too.

===
Personally, I wouldn't bother with this. This kind of code just makes it more
difficult for the user--and they'll find a way around it.

Either by disabling macros or disabling events or by just closing and reopening
the workbook.

And I think it just causes bad feelings among co-workers.



Danny wrote:

Hi Dave,

I'm sorry that I have not explained myseld clearly. I came up with a loan
packaging workbook template with the help of individuals including yourself
in this NG.

Every now and then, I let my officemates use my workbook. I protected the
workbook from printing. When they are done with the loan package, I give them
the "printing password" so they print a maximum of 30 times.

However, due to the "printing password", everytime they click print they are
always asked for the password.

To solve this problem I came with the idea that when the user has the
correct "printing password", the macro I'm asking will open the vba project,
delete the existing before print event and change it with a new one. When the
new before print event is in place, the user will no longer be prompted to
key in the "printing password". Of course, the user will still be limited to
print 30x.

On Mr. Chip Pearson's website, one cannot delete the VBA if its protected.
The macro I'm asking will include my "VBA project password" so it can be
opened and saved.

Thank you.

"Dave Peterson" wrote:

I wouldn't expect most users feel comfortable inside the VBE modifying code.

I don't quite understand what you're doing, but if you allow the users to break
the rule about number of hardcopies, why make it difficult?

Why not just let them do it without any interference?



Danny wrote:

Hi Dave,

The reason why I need it is, I let my officemates use my workbook. In order
for them to print is, they have to have a "printing password" that I provide.

They usually print about 26 worksheets. Everytime they have to print a
worksheet,
they have to use the password.

I'd like to change the Before Print Event (from Mr. Chip Pearson's website)
to

"Cancel = False", but is limited to print 30 times so, they won't have to
use the "printing password" everytime.

I am only giving the "printing password" not the "VBA Password" to other
users.

Thank you.

End Sub

"Dave Peterson" wrote:

There have been posts that suggest that using Sendkeys to go through the menu
system and enter the password, but that's not a robust technique.

I'd never use it in anything that I needed to depend on (or give to others).

Danny wrote:

I'm sorry I did not make myself clear. I know the password because its my own
workbook.

So, can a macro be written for it?

Thanks again.

"JNW" wrote:

I hate to burst your bubble, but you just can't if there is a password on the
file. There is nothing in the code that lets you get around a password. go
into VBA and press F2, select VBIDE for your library and search around for
anything relating to password access. It doesn't exist. The most it will
let you do is see if the file is protected...
--
JNW


"Danny" wrote:

Hi,

I'd like to open my VBA (protected by a password),
delete and replace a module (macro, courtesy of Mr. Chip Pearson's website),
protect the vba project with the same password,
save the file and exit.

When I posted to request the assistance to write a macro for the above
project, I was informed that one CANNOT open and close the VBA project with a
macro.

It's hard to believe that with the sophistication of the program, a macro
command for the above project is not available.

Thank you.





--

Dave Peterson


--

Dave Peterson


--

Dave Peterson