password for workbook

N

Neo1

Hello, How can i set the workbook so that when opened, a dialogu
appears asking for password to open up the workbook before being abl
to read or Read/write anything....

Thanks a lot
From Joh
 
B

Bob Phillips

One simple way, although the password input is not masked

'-----------------------------------------------------------------
Private Sub Workbook_Open()
'-----------------------------------------------------------------
Dim ans
ans = InputBox("Please supply password")
If ans <> "password" Then
Me.Close False
End If
End Sub

'This is workbook event code.
'To input this code, right click on the Excel icon on the worksheet
'(or next to the File menu if you maximise your workbooks),
'select View Code from the menu, and paste the code



--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)
 
N

Neo1

Bob Philips I tried putting in your code but the following error messag
when i opened my spreadsheet model appeared:

Compile error:

Ambiguous name detected: Workbook_open

How can i solve this?

Thanks a lot
From Joh
 
B

Bob Phillips

That means you already have a Workbook_Open procedure. You probably need to
merge them. Can you post the code from the other one?

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)
 
N

Neo1

Yeah it is...


Private Sub Workbook_Open()
Worksheets("Main Menu").Activate
End Sub

Which basically opens up the Main Menu worksheet whenever i open the
spreadsheet model file..

Thanks a lot
From John
 
D

Dave Peterson

I'm not Bob, but you could try this:


Private Sub Workbook_Open()
Dim ans
ans = InputBox("Please supply password")
If ans <> "password" Then
Me.Close False
End If
Worksheets("Main Menu").Activate
End Sub
 
B

Bob Phillips

I was well out of it by this time <g>

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)
 
N

Neo1

There seems to be a problem with the code you gave me...when i open th
excel file all i get is a dialogue box with the password I entered a
the title and then a text box...I tried typing in the password which i
the title and then i click ok and it just closes the spreadshee
model....

How can i fix this?

Thanks
From Joh
 
D

Dave Peterson

Make sure you're typing the password in the correct case (Upper and Lower).

If you're using this code:

Private Sub Workbook_Open()
Dim ans
ans = InputBox("Please supply password")
If ans <> "password" Then
Me.Close False
End If
Worksheets("Main Menu").Activate
End Sub

make sure you type the word "password" (w/o the double quotes) in all lower
case.

You can avoid the open macros (Auto_Open or Workbook_Open) by depressing the
shift key when you open the workbook.

Another way is to turn the macro security level to high (or medium and answer no
to the allow macros prompt). Then open the workbook.
 
S

Saruman

A far simpler way would of been to use the Excel "File Save As" - Tools -
General Options - Password To Open Routine

In the Army, we had a saying, KISS.

Keep
It
Simple
Stupid.

Saruman
 
Top