Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Password Protecting a command button

I need to know how to set a command button, which clears many pages of
information to be there, but only accessable to the right people. E. I.
those with the password. I don't want anyone to clear by accident. Is there
a way to protect only that button and leave the rest of the sheet accessable
to everyone else in the shared workbook? Can this be done with a setting or
with a string of programming. Please help.

A
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Password Protecting a command button

hi A

you could try using a inputbox something like below should give you an
idea of what to do

Option Explicit
Dim mypassword As String

Private Sub CommandButton1_Click()
mypassword = Application.InputBox("Please Enter Password",
"Restricted")
If mypassword = "test" Then 'set your password here
MsgBox ("run your code here") ' add your own code to delete sheets
here
Else
mypassword = Application.InputBox("Incorrect Password try again",
"Restricted") 'try again
End If
End Sub

hope this is of some use for you

S

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 324
Default Password Protecting a command button

My first thought would be to insert a message box in the button's code which
asks for a password. If the password is not given, or "Cancel" is clicked,
the macro will abort. You could either include the password in the code or
have the code refer to a cell on a hidden (and protected) sheet. I woiuld
even go so far as to have the font of that cell white so the password is not
visible to anyone who unhides the sheet.
--
Best wishes,

Jim


"newguyA14" wrote:

I need to know how to set a command button, which clears many pages of
information to be there, but only accessable to the right people. E. I.
those with the password. I don't want anyone to clear by accident. Is there
a way to protect only that button and leave the rest of the sheet accessable
to everyone else in the shared workbook? Can this be done with a setting or
with a string of programming. Please help.

A

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Password Protecting a command button

Note that security in Excel/VBA is very weak, so that anyone determined to
circumvent your password protection will be able to do it. That said, try
something like

Dim PW As String
PW = InputBox("Enter Password")
If StrComp(PW,"CorrectPassword",vbBinaryCompare) < 0 Then
MsgBox "Bad Password"
Exit Sub
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting LLC
www.cpearson.com
(email on the web site)


"newguyA14" wrote in message
...
I need to know how to set a command button, which clears many pages of
information to be there, but only accessable to the right people. E. I.
those with the password. I don't want anyone to clear by accident. Is
there
a way to protect only that button and leave the rest of the sheet
accessable
to everyone else in the shared workbook? Can this be done with a setting
or
with a string of programming. Please help.

A



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Password Protecting a command button

Make the Command Button visible only after the entry in a Text Box of the
correct password. If Active Directory is in use in your network environment,
you may just want to enable particular users, without the bother of a
password.

The following routine sets the Application.Username field to the user's
Active Directory entry. Call this from the Workbook_Open event, or in the
Initialize event of the user form
-------------------------------
Sub GetNameFromAD()
Dim sDisplayName As String
On Error GoTo NoConnection 'If laptop user not logged onto network
Set oADSystemInfo = Nothing

' Get full username from AD
Set oADSystemInfo = CreateObject("ADSystemInfo")

' get AD user object
Set oADsUser = GetObject("LDAP://" & oADSystemInfo.UserName)

' get full name of the current user
sDisplayName = oADsUser.DisplayName

Application.UserName = sDisplayName
Set oADSystemInfo = Nothing
NoConnection:
End Sub
----------------------------

Now reference the Application.UserName to check who the user is.

--
HTH
Roger
Shaftesbury (UK)




"newguyA14" wrote in message
...
I need to know how to set a command button, which clears many pages of
information to be there, but only accessable to the right people. E. I.
those with the password. I don't want anyone to clear by accident. Is
there
a way to protect only that button and leave the rest of the sheet
accessable
to everyone else in the shared workbook? Can this be done with a setting
or
with a string of programming. Please help.

A





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Password Protecting a command button

Ok, I am somewhat of a novice to this. I have built this program, but it has
taken awhile and alot of what I have done I have asked for help on. Can
someone take one of these suggestions and kind of slow it down for me, like a
play by play. I'm not sure whether this would go under the code of the page,
or do I need this under a specific object. the page this is on is called
"Note Tracker" and the command box is "Clear all Messages". Any help is
appreciated.

A


" wrote:

hi A

you could try using a inputbox something like below should give you an
idea of what to do

Option Explicit
Dim mypassword As String

Private Sub CommandButton1_Click()
mypassword = Application.InputBox("Please Enter Password",
"Restricted")
If mypassword = "test" Then 'set your password here
MsgBox ("run your code here") ' add your own code to delete sheets
here
Else
mypassword = Application.InputBox("Incorrect Password try again",
"Restricted") 'try again
End If
End Sub

hope this is of some use for you

S


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 Protecting a command button. newguyA14 Excel Programming 0 April 18th 07 01:34 PM
VB's Command Button vs Form's Command Button Ronald Dodge Excel Programming 3 May 24th 06 02:23 PM
how can I assign a password to a command button Help! Excel Programming 2 January 4th 06 01:52 PM
Password Protecting Nick Excel Discussion (Misc queries) 6 June 30th 05 12:06 PM
Command Button Password Cindy Excel Programming 3 January 14th 04 04:32 PM


All times are GMT +1. The time now is 02:53 PM.

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"