Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Password To Run Macro?

Is there a way to request a password when a macro button is clicked? I
would like to 'lock' down the macros.

Thanks.

G
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default Password To Run Macro?

You could create a userform with a password textbox, which has a
PasswordChar character property so that you can mask it.

--
__________________________________
HTH

Bob

"garyh" wrote in message
...
Is there a way to request a password when a macro button is clicked? I
would like to 'lock' down the macros.

Thanks.

G



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 735
Default Password To Run Macro?

Before your code runs, ask the user for an input, simplest to use an
InputBox then validate the entry against a stored value (password)

simple example......

If InputBox("Enter password to run") < "MyPassword" Then
MsgBox "Wrong password"
Exit Sub
End If
' rest of your code

--

Regards,
Nigel




"garyh" wrote in message
...
Is there a way to request a password when a macro button is clicked? I
would like to 'lock' down the macros.

Thanks.

G


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Password To Run Macro?

That is not too bad to do. Set up a global variable in a standard code
module. Create a userform that allows the user to enter a password. On the
text box set the Password Character to *. Now have your macros check to see
if there is a valic password in the global variable. If so then run the
macro. If not then pop us the userform and let them enter the password. Then
double check the password entered and you are good to go...

--
HTH...

Jim Thomlinson


"garyh" wrote:

Is there a way to request a password when a macro button is clicked? I
would like to 'lock' down the macros.

Thanks.

G

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Password To Run Macro?

Hi,

You could put this as the first lines of your code which gives you 3 chances
to enter the corrrect case sensitive password. It isn't secure because the
passwoord is visible when entered but even if you use a userform textbox to
mask the passowrd that isn't secure either

Do
response = InputBox("Enter password", "Run Macro")
If response < "Mypass" Then
x = x + 1
If x 2 Then Exit Sub
Else
MsgBox "Running macro"
Exit Do
End If
Loop
'your code

Mike

"garyh" wrote:

Is there a way to request a password when a macro button is clicked? I
would like to 'lock' down the macros.

Thanks.

G



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default Password To Run Macro?

if you just want to limit access to macros to your use only, you could as an
idea, do a check on username.

see if this approach may work:

Public Const namecheck As String = "garyh"
Sub mymacro()
Dim myname As String

'get logon name
myname = Environ("UserName")

If myname = namecheck Then

'YOUR MACRO

Else

msg = MsgBox("You Are Not Authorised To Run Macro.", 16, "Warning")

End If
End Sub


if you want to prompt for password then an adding inputbox to probably the
simplest approach.

--
jb


"garyh" wrote:

Is there a way to request a password when a macro button is clicked? I
would like to 'lock' down the macros.

Thanks.

G

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default Password To Run Macro?

Alt + F11 VBAProject €“ Project Properties Protection Lock Project for
Viewing (check) then enter a Password and confirm.

Is that what you want or something else?

Ryan--

--
RyGuy


"Bob Phillips" wrote:

You could create a userform with a password textbox, which has a
PasswordChar character property so that you can mask it.

--
__________________________________
HTH

Bob

"garyh" wrote in message
...
Is there a way to request a password when a macro button is clicked? I
would like to 'lock' down the macros.

Thanks.

G




  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default Password To Run Macro?

How does the user execute the macro? If by clicking a button then in the code
behind the button don't put the macro, instead put the following:

Sub VarifyPWD()
Dim Pwd As String, PwdEntered As String

Pwd = "MyPassword" ' Modify to your chosen password
PwdEntered = InputBox("Please enter password.")

If UCase(PwdEntered) = UCase(Pwd) Then
macro1 'enter the the name of the macro here
Else
MsgBox "Password not valid!", vbCritical
End If
End Sub

In the above code the password will not be case sensitive, if you want the
password to be case sensitive then skip the UCase function

You could create a userform and the textbox which will be used as the
password input, you can asign password charcters like *, so that other people
cannot see what the user enters.

Hope this helps
--
A. Ch. Eirinberg


"garyh" wrote:

Is there a way to request a password when a macro button is clicked? I
would like to 'lock' down the macros.

Thanks.

G

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default Password To Run Macro?

This one is the same as before, but to avoid the user getting a message -
"Password not valid" when he cancels the Inputbox you should put the
following line of code after the line: 'PwdEntered = InputBox("Please enter
password.")', as follows:

PwdEntered = InputBox("Please enter password.")
If PwdEntered = "" Then Exit Sub
--
A. Ch. Eirinberg


"Howard31" wrote:

How does the user execute the macro? If by clicking a button then in the code
behind the button don't put the macro, instead put the following:

Sub VarifyPWD()
Dim Pwd As String, PwdEntered As String

Pwd = "MyPassword" ' Modify to your chosen password
PwdEntered = InputBox("Please enter password.")

If UCase(PwdEntered) = UCase(Pwd) Then
macro1 'enter the the name of the macro here
Else
MsgBox "Password not valid!", vbCritical
End If
End Sub

In the above code the password will not be case sensitive, if you want the
password to be case sensitive then skip the UCase function

You could create a userform and the textbox which will be used as the
password input, you can asign password charcters like *, so that other people
cannot see what the user enters.

Hope this helps
--
A. Ch. Eirinberg


"garyh" wrote:

Is there a way to request a password when a macro button is clicked? I
would like to 'lock' down the macros.

Thanks.

G

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Password To Run Macro?

What do you mean by "lock down" the macros?

This addition will prevent a macro from running if pword is incorrect but
you must lock the project from viewing if you don't want the users to see
the password by snooping at the VBE

Dim pword As String
pword = InputBox("enter password")
If pword < "justme" Then
Exit Sub
Else
do your stuff
End If


Gord Dibben MS Excel MVP

On Mon, 16 Mar 2009 10:33:07 -0700, garyh
wrote:

Is there a way to request a password when a macro button is clicked? I
would like to 'lock' down the macros.

Thanks.

G




  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 79
Default Password To Run Macro?

This works like a charm! Exactly what I was looking for!
Thanks,
Valerie

"Nigel" wrote:

Before your code runs, ask the user for an input, simplest to use an
InputBox then validate the entry against a stored value (password)

simple example......

If InputBox("Enter password to run") < "MyPassword" Then
MsgBox "Wrong password"
Exit Sub
End If
' rest of your code

--

Regards,
Nigel




"garyh" wrote in message
...
Is there a way to request a password when a macro button is clicked? I
would like to 'lock' down the macros.

Thanks.

G



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Password protection in macro ( Anybody can view my password in VB Sherees Excel Discussion (Misc queries) 2 January 24th 10 10:05 PM
Macro on Password acss Excel Programming 1 July 21st 08 05:36 PM
PASSWORD REMOVAL I have the password to open the file and the password to modify the file now how to remove them LJ[_4_] Excel Programming 0 April 27th 06 03:18 AM
How to see macro code of a password protected macro without a password? Dmitry Kopnichev Excel Worksheet Functions 5 October 27th 05 09:57 AM
How to see macro code of a password protected macro without a password? Dmitry Kopnichev Excel Programming 5 October 27th 05 09:57 AM


All times are GMT +1. The time now is 08:43 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"