Another protect proble.

  • Thread starter Thread starter Tom
  • Start date Start date
T

Tom

Hello,

now I need protect macro (againts using Ctrl-Break) in Sub Auto_open(), but
this dosnt work:

With Application
.EnableCancelKey = xlDisabled
End With

Can you help me. I'd like to protect all macros at once, is it possible?

Thanks
Tom
 
Hi Tom

Firstlu Auto_Open is old hat. It has been replaced with the
Workbook_Open event found in the Privtate Module of the Workbook Object,
"ThisWorkbook".

Placing

Application.EnableCancelKey = xlDisabled

As the first line in the Workbook_Open event should prevent the use of
Esc or Ctrl+Break.

Keep in mind this statement from the VBA help

The EnableCancelKey property is always reset to xlInterrupt whenever
Microsoft Excel returns to the idle state and there's no code running.
To trap or disable cancellation in your procedure, you must explicitly
change the EnableCancelKey property every time the procedure is called.




** Posted via: http://www.ozgrid.com
Excel Templates, Training, Add-ins & Business Software Galore!
Free Excel Forum http://www.ozgrid.com/forum ***
 
Thanks,

and how can I use workbook_open. Auto_Open I used like this:

Auto_Open ()

..
..
..

End Sub

Tomas
 
It's not really better, just the preffered method. Since Excel 97 there
have been Workbook and Worksheet Events. These replace Auto_Open &
Auto_Close. They only still work for backward compatibility.

** Posted via: http://www.ozgrid.com
Excel Templates, Training, Add-ins & Business Software Galore!
Free Excel Forum http://www.ozgrid.com/forum ***
 
I think you're going to have to set this each time a macro starts.

From xl2002's help for .enablecancelkey:

The EnableCancelKey property is always reset to xlInterrupt whenever Microsoft
Excel returns to the idle state and there's no code running. To trap or disable
cancellation in your procedure, you must explicitly change the EnableCancelKey
property every time the procedure is called.

If you're trying to stop the users from seeing your code, you can keep most out
of it by protecting the project.

Inside the VBE, Tools|VBAProject Properties|Protection Tab
is where you can password protect your project.

The users can still hit ctrl-break, but most/all won't see the code. (Passwords
can be broken by people who really want to see that code, though.)
 
Back
Top