Start up security

  • Thread starter Thread starter will07
  • Start date Start date
W

will07

Is it possible to enter code into an excel file that looks for a network user
name as the file opens. If your user name is not on the network, then the
file will not open. I realise that security for Excel is dodgy at the best
of times, but it is a start.

I have set range passwords for the worksheets, but need to prevent the file
from opening.

Thanks
 
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If lngX <> 0 Then
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = ""
End If
End Function
 
Thanks Steven, A big help.

I am not experienced in entering code but want to learn more

Should I enter this code in the VB editor code under "this workbook (Code)"
- Workbook - Open

Thanks again
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top