PDA

View Full Version : [SOLVED:] Password in Macro



excelliot
06-30-2005, 01:58 AM
Hi

can i put password to run macro,
i.e. macro can not be run untill i supply password

:beerchug:

doctordoggie
06-30-2005, 02:51 AM
I don't think the security settings in Office are flexible enough for this.

However, you can write your own (obviously you'll need to password protect your project so casual users won't be able to hack your code)!

If you set up a form with a textbox in there, there is a property called PasswordChar which you can set (to '*' or somesuch) which you can then check against using whatever encryption you may or may not choose to use.

Full instructions and a more detailed account can be found here:

http://support.microsoft.com/default.aspx?scid=kb;en-us;212708

Hope this is of some help.

excelliot
06-30-2005, 05:54 AM
No u did not got me,
i want user to give password for running given macro as supplied while opening protected excel file
so data is not modified by unauthorised person

Justinlabenne
06-30-2005, 07:48 PM
1) Excel is not secure. If someone wants at your workbook. They can probably get it.

2) Try this to get you started. Very cheap, basic example.

sheeeng
06-30-2005, 07:51 PM
Simple and yet useful.....Can we hide the sheet when the dialog box for password is shown? Because ppl can see the data in sheet before entering data......


Thx in advance,

Justinlabenne
06-30-2005, 08:26 PM
Like this?

sheeeng
06-30-2005, 08:55 PM
Sorry...
Not like this. I still can see the data on sheet.....
What I mean is to hide to sheet data...(crucial)..

Thx.

Justinlabenne
06-30-2005, 09:01 PM
You would remove the password from the sheet. It is only there so "you" know what it is for the example workbook provided. Just unprotect the sheet (no password) and erase the cell.contents

You just have to remeber the password, and it is stored within the userform's code module if you want to change it to you own.

excelliot
07-06-2005, 04:59 AM
thanks let me check it now

excelliot
07-06-2005, 05:03 AM
It gives following error code
user name u have specified is invalid
pls give correct username

& also my right clik is also disabled

shades
07-06-2005, 06:02 AM
What version are you using. I am using XL 2003 on Win 2K and it works fine for me.

Scottie P
07-06-2005, 10:13 PM
Sorry...
Not like this. I still can see the data on sheet.....
What I mean is to hide to sheet data...(crucial)..

Thx.

Here Sheeeng, try this.
Is this what you're looking for?


**EDIT**

If anyone downloaded the first version that I posted, dump it and try this one.
I had to update something in the file (which I had forgotten about previously).
No danger, just old contact info left in from days gone by is all.

Scott

sheeeng
07-06-2005, 10:26 PM
Here Sheeeng, try this.
Is this what you're looking for?


**EDIT**

If anyone downloaded the first version that I posted, dump it and try this one.
I had to update something in the file (which I had forgotten about previously).
No danger, just old contact info left in from days gone by is all.

Scott

What is the password? Thx. :friends:

....

Ok, I found it...pretty good....i like it.
Thx. :friends:

BTW, what is a wookie? :dunno

Scottie P
07-06-2005, 10:36 PM
Star Wars movie character...Big hairy guy. LOL!

The only thing that is not possible with this password input (as far as I know) is masking the password as it is being entered. To do that, the input would need to be built on a small userform containing a textbox - then the password could be masked to look like ***** instead of 123abc.

Scott

sheeeng
07-06-2005, 10:38 PM
Star Wars movie character...Big hairy guy. LOL!

Scott

The wookie...is he...I cannot remember...:old:
What is he called? besides wookie.

Scottie P
07-06-2005, 10:40 PM
Chewbakka? Something like that...Jake would know the correct name/answer for this one.

http://www.vbaexpress.com/scott/wookie2.jpg

excelliot
07-06-2005, 11:47 PM
Here Sheeeng, try this.
Is this what you're looking for?


**EDIT**

If anyone downloaded the first version that I posted, dump it and try this one.
I had to update something in the file (which I had forgotten about previously).
No danger, just old contact info left in from days gone by is all.

Scott

Its cool

this is wat i was looking for
but i have to little customize it?

thanks

:hi::cloud9:

excelliot
07-13-2005, 02:30 AM
ok no more issues

jetted
07-14-2005, 09:25 AM
Hi Scott

I like what you have done. .

You can mask the password by ***** if use api (see attached document). This is not my code, i can remember where I got it, but enjoyed...

austenr
07-14-2005, 10:57 AM
Trying to modify Scott's solution to where on open it shows sheet2 and asks for the password to sheet1 which is the sheet I want protected. Any help would be appreciated. Thanks

Scottie P
07-14-2005, 11:00 AM
Jetted,

I am sorry - I never received notification on this post.
I did (as a matter of fact) find some API just last night that I had here for a while. It likely came from Ivan or Colo a couple of years ago.
I didn't look at it but dropped a shortcut on my desktop so that I could check it out when I had some time.
I will grab your sample and check it out as well. Since coding practices have gotten a little tighter over the last couple of years, I am curious to see the differences in the two. :)

thank you for stopping in on this one!

jetted
07-14-2005, 11:11 AM
Hi Austenr

Open visual basic editor, double click on workbook and find and replace ("Sheet2") by ("Sheet1")

This should now protect sheet1

Thanks

Zack Barresse
07-14-2005, 11:22 AM
The only thing that is not possible with this password input (as far as I know) is masking the password as it is being entered. To do that, the input would need to be built on a small userform containing a textbox - then the password could be masked to look like ***** instead of 123abc.
Have you not used Daniel Klann's code? It's superb, IMHO.

Found here: http://www.danielklann.com/excel/hiding_text_in_a_vba_inputbox.htm