View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
NickHK NickHK is offline
external usenet poster
 
Posts: 4,391
Default Only opening a workbook by User Name or Machine Name???

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"
wrote in message
...

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 Lloyd
------------------------------------------------------------------------
Simon Lloyd's Profile:

http://www.excelforum.com/member.php...fo&userid=6708
View this thread: http://www.excelforum.com/showthread...hreadid=553507