View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
Ed Ed is offline
external usenet poster
 
Posts: 279
Default Autoshut Excel if password is incorrect

Hello Gorb, that is a very good idea... this has more of protection that what
I proposed before... but once macros are enabled I would like to make sure
that just certain persons who know the correct password can use it.

For me its the same if the password is typed into a certian cell or in a
dialog box, the only thing I care about is that when you enable macros, first
thing it does is it asks for the password, if the password is incorrect then
it closes the file, if not it leaves you work in it.

Some while ago in this discussion group I came upon this macro (thanks to
the author):

-------------------------
Dim DownTime As Date

Sub SetTime()
DownTime = Now + TimeValue("00:00:05")
Application.OnTime DownTime, "ShutDown"
End Sub

Sub ShutDown()
ThisWorkbook.Save
ThisWorkbook.Close
End Sub
-------------------------

So I was thinking maybe I can have a "IF" statement through VBA which
activates this macro or a similar that shuts down the workbook, the thing is
I don't know how to prompt to ask for the password and to use it on the IF
statement... Im learning bit by bit VBA but still can't manage such things!
So whatever solution that gives the result is greatly appreciated!

thanks!




"Gord Dibben" wrote:

Ed

Can be done but what contingency will you have if user chooses to disable macros
when opening the workbook?

Your macro won't run but the workbook will still open in it's useless state.

To properly set up for this type of operation, you would have code when closing
the workbook that hides all sheets except one which has nothing but a message
saying "You have disabled macros. Close workbook and re-open with macros
enabled"

If macros are enabled, workbook opens with sheets unhidden and macros ready to
go.

How do you want to proceed?


Gord Dibben MS Excel MVP

On Thu, 21 Dec 2006 11:20:01 -0800, Ed wrote:

Hello, I have a workbook that functions mainly through Macros, if you choose
not to run then then you can't get much done. I would like to have a macro
upon opening of the Workbook where a dialog box or whatever prompts the user
to type in a password, if the password is correct then nothing happens, but
if it is not, then it shuts down Excel... anybody know how?

thanks!