Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Unprotect on open

I need code that will check the network username and unprotect a worksheet
when the workbook opens. So on open it will check the username and then
unlock the worksheets if it matches a list of approved users. If not, it
will remain locked.

I am using excel 2007.

Thanks for all the help in advance.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 160
Default Unprotect on open

I use an Access database on our shared network to validate against. You will
need to add the appropriate references.

Public Pass As Boolean
Dim cn As ADODB.Connection, rs As ADODB.Recordset, intColIndex As Integer
Public Sub UrIdentity()
Pass = False
Set TargetRange = Range("X1")
Set cn = New ADODB.Connection
DBFullName = "P:\Permanent_Data\Patrick\Security.mdb"
TableName = "Authorized"
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & DBFullName &
";"
Set rs = New ADODB.Recordset
With rs
.Open "SELECT * FROM " & TableName & " WHERE Emp LIKE '" &
UCase(frmLogIn.txtUserNumb) & "'", cn, , , adCmdText
For intColIndex = 0 To rs.Fields.Count - 1 ' the field names
TargetRange.Offset(0, intColIndex).Value = rs.Fields(intColIndex).Name
Next
TargetRange.Offset(0, 0).CopyFromRecordset rs ' the recordset data
End With
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
If Range("X1").Value < "Emp" And Range("Y1").Value < "" Then
Pass = True
Else
Pass = False
End If
Range("X1:Y1").ClearContents
Range("A2").Select
End Sub
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Unprotect on open

On Aug 3, 10:46 am, wagz wrote:
I need code that will check the network username and unprotect a worksheet
when the workbook opens. So on open it will check the username and then
unlock the worksheets if it matches a list of approved users. If not, it
will remain locked.

I am using excel 2007.

Thanks for all the help in advance.


Environ("Username") will return the name of the user. You could use
that to validate against a source of your choosing.

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
How do I unprotect a spreadsheet? Sofiya Excel Worksheet Functions 1 October 13th 08 04:30 PM
unprotect workbook Deb Excel Discussion (Misc queries) 2 February 9th 07 07:40 PM
Unprotect a worksheet FRAZZLED New Users to Excel 0 May 30th 06 05:06 PM
Unprotect worksheet via VBA Mike Echo Excel Worksheet Functions 2 March 19th 06 04:52 AM
Unprotect Conditional Formatting Excel Discussion (Misc queries) 3 September 5th 05 02:49 PM


All times are GMT +1. The time now is 04:37 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"