PDA

View Full Version : Solved: password protected file



davidw
11-12-2008, 10:06 AM
I have a file (data file) that is a shared file for the explicid reason of producing a history of input. This file has code I added that requires a password to access it.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Private Sub Workbook_Open()

x = InputBox("passwordbox caption", "Title at the top of the Box")
If x <> "My Passord" Then ActiveWorkbook.Close False

End Sub
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

I have 2 questions.
1. How can I modify this code so that it will Put * in when I type in the password. As it is now it types in the password for anyone watching to see.

2, This being the data file, I have another file (run file) containing macros that everyone has access to. The run file has to open the data file to copy data. What would be the code I would need to put into the run file to get past the password protection?

Thanks for the help.

lucas
11-12-2008, 10:21 AM
I'm not sure you can mask the password in a messagebox or inputbox.

You can using a small userform and textbox. Set the textbox PasswordChar property to *

You should make an addin out of your run file. I'm not really following what you want to do here.......you have a macro that runs on a password protected file, is that correct? So you need to unprotect it and then run your code and then re-protect it.

Is it workbook protected or sheet protection......

RonMcK
11-12-2008, 10:40 AM
You might find Simon Lloyd's kBase article on protecting a worksheet, helpful. His instructions show you how to create a userform as Lucas recommended. Click for KB 931 (http://vbaexpress.com/kb/getarticle.php?kb_id=931)

Cheers,

davidw
11-12-2008, 11:20 AM
I cant use the shared file to run macros in due to the history picking up all the changes. I have a data file that is shared and i put my data in it. I have a 2nd file that contains macros and is not shared. This way my shared file history does not pick up on any of the macro changes. I copy all the data from the data file to the macro file and run macros. I am the only one who needs access to the data file. Everyone uses the macro file. I have the code which requires a password to open the data file. I need to code that will allow the macro file(when opened) to copy data from the data file to the macro file. At present if someone runs the macro file it requires them to put in my password to continue. Cant let them have it.

davidw
11-12-2008, 11:23 AM
i read my own post and am confused.

data file.xls(shared) = this file is actually not for others to see. I only changed it to share for history purposes only.

macro file.xls = This file is the one that everyone has access to and runs macros out of. It contains protected sheets and macros.

lucas
11-12-2008, 11:30 AM
I have a data file that is shared and i put my data in it. I have a 2nd file that contains macros and is not shared. This way my shared file history does not pick up on any of the macro changes. I copy all the data from the data file to the macro file and run macros. I am the only one who needs access to the data file.

I'm confused.

lucas
11-12-2008, 11:32 AM
Can you expain what this means:
data file.xls(shared) = this file is actually not for others to see. I only changed it to share for history purposes only.

davidw
11-12-2008, 11:42 AM
data file.xls(shared) When you change a files status to shared it puts (shared) to the right of the name of the file at the top of the screen on excel.

lucas
11-12-2008, 11:53 AM
David, You have a file with macros that should copy data from a data file to work on.

You share the file with macro's but you want to keep people from using it using password protection.

What am I missing?

davidw
11-12-2008, 11:59 AM
I share the file with macros. I dont want people to access the data file.

lucas
11-12-2008, 12:06 PM
so when you run a specific macro in the file with macro's(runfile) you want it to unprotect the data file so the macro can run on it but you want it to ask for a password before it will proceed?

or is the data file not protected at all, just not accessable to others and you want the macro to ask for a password before running.....

Are we getting close?

davidw
11-12-2008, 12:11 PM
lol getting close.
The data file asks for a password using the code above. This is fine and dandy for manually opening the file and updating the data. However when the macro file is run(by other employees) it does the same thing as though I were opening it. It asks for a password. They dont have the password. When the macro runs I want it to open the data file and supply the data file with the password without employee input.

lucas
11-12-2008, 12:41 PM
Put this in your macro to open the file:

Workbooks.Open "C:\Users\Steve\Documents\book1.xls", Password:="test"


you will have to change the path and the password.

davidw
11-12-2008, 12:53 PM
I put it in but it still asks for password

Workbooks.Open "C:\Users\Owner\Documents\Kevin\AAA Testing macros\administrators input program.xls", Password:="david"

lucas
11-12-2008, 01:03 PM
hmm.....it works for me. Try the attached. Unzip them to the same directory and run the runme.xls.

You do understand that your password will be vulnerable in the vbe and if a user goes in there they can easily obtain it, right?

lucas
11-12-2008, 01:04 PM
When you password protected the data file, did you choose just a password or did you lock it down as read only?

davidw
11-12-2008, 01:06 PM
this is what i put in the file


xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Private Sub Workbook_Open()

x = InputBox("password needed", "Title at the top of the Box")
If x <> "david" Then ActiveWorkbook.Close False

End Sub
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

The file is not read only

lucas
11-12-2008, 01:09 PM
little by little I am pulling the teeth that are the substance of your problem.........

davidw
11-12-2008, 01:13 PM
i downloaded your file and it seems to run great but....

How did you password protect the file.
Mine has code in it that requires a password. I didnt see that in yours

lucas
11-12-2008, 01:17 PM
try password protecting your workbook like this:

remove the onopen sub that you have used and then go to file-saveas

go to tools at the top right of the dialog box and select general options.

type your password in there in only the top box, the one marked: password to open. That's it. You will be asked to verify it after you click on ok........then save it and try my code again.

This way if you open the data file by it'self the password will be masked as you type it.

davidw
11-12-2008, 01:34 PM
Bingo....That was it. Now I have my data file protected/ making history of all sheet changes/ and accessable by another file without giving up my password.. Thank you for being so understanding.

davidw
11-12-2008, 01:37 PM
how do I document this issue as being solved

lucas
11-12-2008, 01:40 PM
Mark it solved using the thread tools at the top of the page.

Glad we got to the bottom of it.

RonMcK
11-12-2008, 02:42 PM
Gee, Steve ('er, Lucas),

No msg from DavidW telling you want a wonderful job you've done for him?

Edited in: WHOOPS! My bad, I forgot to look at the 2nd page of msgs; (Sorry, DavidW, mea culpa.)

So, did you have to pull all the molars? :rotlaugh:

Cheers!

lucas
11-12-2008, 03:36 PM
Couple of wisdom teeth too Ron. We finally got it though.

Asking your question in a way that makes it clear to those helping you is hard for many who visit here. I'm trying to get my dental license.