Only opening a workbook by User Name or Machine Name???

  • Thread starter Thread starter Simon Lloyd
  • Start date Start date
S

Simon Lloyd

Hi all, is there a way of capturing either the User name or Machine name
that the workbook is being opened on?, i would like to send a workbook
to some people but do not want to allow them to open the workbook on
any other machine than their own so if their machine is called Office1
then they can only open it on there else close the workbook, all the
network users are narrowed to being able to log on on one machine only
i do not want them taking the workbook home!, single machine users
outside the company i would like them to only open the workbook on the
machine that recieved the e-mail with the workbook in.

probably an impossible task..........but maybe just maybe one of you
may have an angle on this!

Regards,
Simon
 
Simon,
For the computer name, see the earlier post today titled "computer_name".
As for the user name, Application.UserName gives you name shown in Help >
About Excel..

Or for the logged in user:
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA"
(ByVal lpBuffer As String, nSize As Long) As Long

Private Sub CommandButton1_Click()
Dim strUserName As String
Dim RetVal As Long
'Create a buffer
strUserName = String(100, Chr$(0))
'Get the username
RetVal = GetUserName(strUserName, 100)
'strip the rest of the buffer
Debug.Print Left$(strUserName, InStr(strUserName, Chr$(0)) - 1)
End Sub

How you decide which is valid is up to you.

NickHK

"Simon Lloyd" <[email protected]>
wrote in message
news:[email protected]...
 
I would probably use a bit of API wizardry:

' API dec
Declare Function Get_User_Name Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

' Function:

Function GetUserName() As String
Dim lpBuff As String * 25
Get_User_Name lpBuff, 25
GetUserName = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)
End Function

' Useage:

Dim strCurrentUser as String
strCurrentUser = GetUserName
If strCurrentUser <> "Simon Lloyd" Then
MsgBox "You are not authorised to view this Workbook"
Else
' open
End if

HTH

Haresoftware
 
Thanks for the replies, i have no idea what API is and i would not be at
liberty to install anything on anyones machine (it would be a nightmare
too!), does the get user name not pick up on the machine name?, does
the user of Excel always have a user name? if so then the get user name
would be fine, i would just have to send a workbook to each user to
collect their user name and then code their name in, am i right in
assuming that when it does Get UserName i can have that user name
stored in a cell so when i get the workbook back i can copy the name
out from that?

regards,
Simon
 
Hi all, Does anyone know if every time excel is opened on a machine if
it has a user or machine name?, i would still like to achieve my
previous post above!

regards,
Simon
 

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